Here is the following table code created dynamically and I want to get the last 2 values stored in TD. the last td value is in the form of "key-value-pair". I want to display something like below:
<tbody>
{{#items}}
<tr>
<td>{{name}}</td>
<td>{{description}}</td>
<td id="newval">{{new_value}}</td>
<td id="oldval">{{old_value}}</td>
</tr>
{{/items}}
</tbody>
here is the json obtained from the server:
{
"result":"OK",
"items":[
{
"name":"abc",
"description":"desc",
"new_value":{
"description":"newvalue"
},
"old_value":{
"description":"oldvalue "
}
},
{
"name":"abc3",
"description":"desc2",
"new_value":{
"interval":"newvalue2"
},
"old_value":{
"interval":"oldvalue2 "
}
}
]
}
here is the js:
$.each(lists,function(i,items){
for (var key in items) {
if(key == 'new_value'){
for(value in items[key]){
$("td#newval").html(value + " : " +items[key][value]);
}
}
}
});
Similarly I'm doing it for the old value, just replacing the "td" id and value. but what is happening is only the first td gets updated with all the values of "new_value" in the array and the remaining td's are rendered blank. I want to display in such a way that it will loop through the array and find the key value pair associated with the "new_value" object and render both values for the respective td's.
<td>description: newvalue</td>
<td>interval: newvalue2</td>
how can i achieve this? Thanks!