I use the following code to populate my HTML with JSON. The problem is that I'm afraid this code will be inefficient if the number of records that I get from the service call are large (200 or more).
Are there ways I can change my code to make sure this won't be an issue? Or is my code fine as it stands?
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script>
var jsonObj = {
"products": [
{
"ImageName": "product1.png",
"Description": "Yummy choco"
},
{
"ImageName": "product2.png",
"Description": "candy villa"
},
{
"ImageName": "product3.png",
"Description": "vanilla icecream"
}
],
}
$(document).ready(function() {
for(var key = 0; key < jsonObj.products.length - 1; key++) {
var domStructure ='\
<tr>\
<td>\
<img src="' + jsonObj.products[key].ImageName + '">\
</td>\
<td>'
+ jsonObj.products[key].Description +
'</td>\
</tr>';
$('#tableProducts').find('tbody').append(domStructure);
}
});
</script>
</head>
<body>
<table id="tableProducts"><tbody></tbody></table>
</body>
</html>