Im making a table from JSON using jQuery but i'm struggling to get the last column to render due to the structure of the JSON, also the other columns do not quite display the way i was looking for.
I've tried using $.each and a for loop for the last column but nothing i've tried has fixed it.
The JSON looks like:
{
"countries": ["US", "UK", "France", "Germany"],
"months": ["May-2012", "June-2012", "July-2012"],
"types": [{
"type": "Democrat"
}, {
"type": "Republican"
}, {
"type": "Green"
}, ]
}
And my jQuery is:
var target = $('#targettable');
target.empty();
$(target).append($('<tr />')
.append($('<th />').text('Countries'))
.append($('<th />').text('Months'))
.append($('<th />').text('Types')));
$('<tr>')
.append($('<td>', {
'text': myJSON.countries
}))
.append($('<td>', {
'text': myJSON.months
}))
.append($('<td>', {
'text': myJSON.types.type
}))
.appendTo(target);
i made a fiddle of it http://jsfiddle.net/ZukKR/
The last column doesnt show at all and the other 2 arent displaying as a wanted, i was thinking it would create a row per item.
So basically a list of countries in one column, a list of months in the next column and a list of types in the last column. Not sure what else i could try?