2

I have json data like this

{
    Qty:[61.0,0.0,8.0],
    Name:["2009 A","2009 B","2009 C "]
}

and I have to display it in tabular format in html such that all the three elements should be displayed in different rows of the table.It should also be able to contain single name and qty respectively and multiple too (if needed ). Any help would be appreciated in this regard.

1
  • so... what have you tried so far? Commented Nov 17, 2016 at 10:06

1 Answer 1

2

You can see below code how it iterate through $.each loop

$(document).ready(function (e) {
        var t = { Qty: [61.0, 0.0, 8.0], Name: ["2009 A", "2009 B", "2009 C "] }
        $.each(t.Qty, function (i, ele) {
            $("#content").append("<tr><td><input type='checkbox' /></td><td>" + parseFloat(t.Qty[i]).toFixed(1) + "</td><td>" + t.Name[i] + "</td></tr>");
        })
    })
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
<table>
    <thead>
        <tr>
            <th>Select </th>
            <th>Qty</th>
            <th>Name</th>
        </tr>
    </thead>
    <tbody id="content">
    </tbody>
</table>
	

Sign up to request clarification or add additional context in comments.

1 Comment

If i have to display it with checkboxes too then what modification is needed?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.