Hi im trying to Read json data and display data in nested table i have also give my expected result and also posted my script which i have tried.
my Data.json
{"Data":[
{
"label":"node1",
"color":"red",
"children":[
{
"label":"vip1",
"color":"red",
"children":[
{
"label":"obj1",
"color":"gray",
"id":"539803eae4b0ffad82491508"
},
{
"label":"obj2",
"color":"green",
"id":"5395635ee4b071f136e4b691"
},
{
"label":"obj3",
"color":"green",
"id":"539803e4e4b0ffad82491507"
}
],
"id":"53956358e4b071f136e4b690"
},
{
"label":"vip2",
"color":"blue",
"id":"539803f2e4b0ffad82491509"
}
],
"id":"5395634ee4b071f136e4b68e"
},
{
"label":"node2",
"children":[
{
"label":"vip1",
"color":"green",
"id":"539803eae4b0ffad82491501"
},
{
"label":"vip2",
"color":"green",
"id":"5395635ee4b071f136e4b694"
}
],
"id":"5395637fe4b071f136e4b692"
},
{
"label":"node3",
"color":"red",
"children":[
],
"id":"5395637fe4b071f136e4b692"
}
]
}
My script
<script>
$.getJSON( "data/widgetData.json", function( data ) {
$('#widget').append('<table cellspacing="0" align="center" width="600" cellpadding="0" style=" border:3px solid black;">');
var table = $('#widget').children();
table.append( '<tr height="30" style="background-color:black"><td>Title</td></tr>' );
$.each(data.widgetData, function(index0, v) {
//alert(v.color);
table.append( '<tr height="180" style="background-color:'+v.color+'"><td>'+v.label+'</td></tr>' );
$.each(v.children, function (index1, w) {
//alert(w.label);
table.append( '<tr height="180" style="background-color:'+w.color+'"><td>'+w.label+'</td></tr>' );
$.each(w.children, function (index2, x) {
// alert(x.label);
});
});
});
table.append('</table>');
});
</script>
Please help me to achieve this and let me whats wrong with my script