Ive got this code:
loadData : function(jsonArray) {
var id = $(this).attr("id");
for(var i in jsonArray) {
$("#"+id+" tbody").append('<tr class="entry-details page-1 entry-visible" id="entry-'+i+'"></tr>');
var header = {
1: "time",
2: "project",
3: "task"
}
var col = 1;
while(col <= jsonArray[i].length) {
$("#"+id+" tbody #entry-"+i).append("<td>"+jsonArray[i][header[col]]+"</td>")
col++
}}
它将接受类似以下的JSON数组:
{"1":{"project":"RobinsonMurphy","task":"Changing blog templates","time":"18\/07\/11 04:32PM"},"2":{"project":"Charli...
代码应该循环遍历行(它已经做到了),然后循环遍历数据的列。
我面临的问题是,为了将列数据放在正确的列中,我需要计算一行返回多少个数据。我尝试过 jsonArray[i].length,但这会返回未定义。
任何帮助都将不胜感激。