Is there a really easy way I can take an array of JSON objects and turn it into an HTML table, excluding a few fields? Or am I going to have to do this manually?
Make a HTML Table from a JSON array of Objects by extending $ as shown below
$.makeTable = function (mydata) {
var table = $('');
var tblHeader = "";
for (var k in mydata[0]) tblHeader += "" + k + " ";
tblHeader += " ";
$(tblHeader).appendTo(table);
$.each(mydata, function (index, value) {
var TableRow = "";
$.each(value, function (key, val) {
TableRow += "" + val + " ";
});
TableRow += " ";
$(table).append(TableRow);
});
return ($(table));
};
and use as follows:
var mydata = eval(jdata);
var table = $.makeTable(mydata);
$(table).appendTo("#TableCont");
where TableCont is some div
- 热议问题