所以我能够成功地从我的JSON对象中提取数据,我遇到的问题是数据是四重的。有人能告诉我为什么会这样吗?我以前从未见过这个。这是JS:
jQuery(function() {
jQuery.getJSON(NewConvData, function(data){
var channelHTML = ''
jQuery.each(data, function(i){
console.log(data);
for (var i in data.results) {
channelHTML += '<tr><td class="tg-yw4l">' + data.results[i].call_mine_status + '</td><td class="tg-yw4l">' + data.results[i].cdr_source + '</td><td class="tg-yw4l">' + data.results[i].tracking_number + '</td><td class="tg-yw4l">' + data.results[i].disposition + '</td><td class="tg-yw4l">' + data.results[i].duration + '</td><td class="tg-yw4l">' + data.results[i].external_id + '</td><td class="tg-yw4l">' + data.results[i].id + '</td><td class="tg-yw4l">' + data.results[i].is_outbound + '</td><td class="tg-yw4l">' + data.results[i].ouid + '</td><td class="tg-yw4l">' + data.results[i].repeat_call + '</td><td class="tg-yw4l">' + data.results[i].caller_id + '</td><td class="tg-yw4l">' + data.results[i].calldate + '</td><td class="tg-yw4l">' + data.results[i].ringto_number + '</td><td class="tg-yw4l"><a href="' + data.results[i].file_url + '">Recorded Call</a></td></tr>';
}
});
jQuery('#conv_table').append(channelHTML);
});
});
以下是Fiddle link
答案 0 :(得分:1)
您有两个循环each
和for
都检查
var channelHTML = ''
for (var i in data.results) {
channelHTML += '<tr><td class="tg-yw4l">' + data.results[i].call_mine_status + '</td><td class="tg-yw4l">' + data.results[i].cdr_source + '</td><td class="tg-yw4l">' + data.results[i].tracking_number + '</td><td class="tg-yw4l">' + data.results[i].disposition + '</td><td class="tg-yw4l">' + data.results[i].duration + '</td><td class="tg-yw4l">' + data.results[i].external_id + '</td><td class="tg-yw4l">' + data.results[i].id + '</td><td class="tg-yw4l">' + data.results[i].is_outbound + '</td><td class="tg-yw4l">' + data.results[i].ouid + '</td><td class="tg-yw4l">' + data.results[i].repeat_call + '</td><td class="tg-yw4l">' + data.results[i].caller_id + '</td><td class="tg-yw4l">' + data.results[i].calldate + '</td><td class="tg-yw4l">' + data.results[i].ringto_number + '</td><td class="tg-yw4l"><a href="' + data.results[i].file_url + '">Recorded Call</a></td></tr>';
}
jQuery('#conv_table').append(channelHTML);
});
答案 1 :(得分:1)
不要为同一件事使用两个循环,删除
for (var i in data.results)
此循环并按jQuery.each(data, function(i)
修改jQuery.each(data.results, function(i)
。
“守则”将完美运作,不会重复。
这是小提琴链接Fiddle link