使用jQuery/Javascript迭代JSON
我试图用JSON数据填充一个表。当我运行下面的脚本时,我只得到最后一个条目10。我必须做一些使用jQuery/Javascript迭代JSON,javascript,jquery,json,Javascript,Jquery,Json,我试图用JSON数据填充一个表。当我运行下面的脚本时,我只得到最后一个条目10。我必须做一些.append()之类的事情。我试着把它放进去,但它什么也没回来 $(function() { $('#ReportedIssue').change(function() { $.getJSON('/CurReport/GetUpdatedTableResults', function(json) { //alert(json.GetDocumentResults.length);
.append()
之类的事情。我试着把它放进去,但它什么也没回来
$(function() {
$('#ReportedIssue').change(function() {
$.getJSON('/CurReport/GetUpdatedTableResults', function(json) {
//alert(json.GetDocumentResults.length);
for (var i = 0; i < json.GetDocumentResults.length; i++) {
$('#DocumentInfoTable').html(
"<tr>" +
"<td>" + json.GetDocumentResults[i].Document.DocumentId + "</td>" +
"<td>" + json.GetDocumentResults[i].Document.LanguageCode + "</td>" +
"<td>" + json.GetDocumentResults[i].ReportedIssue + "</td>" +
"<td>" + json.GetDocumentResults[i].PageNumber + "</td>" +
"</tr>"
)
};
});
});
});
$(函数(){
$('#ReportedIssue')。更改(函数(){
$.getJSON('/currenport/getUpdateTableResults',函数(json){
//警报(json.GetDocumentResults.length);
for(var i=0;i
谢谢,
Aaron您的代码包含以下内容:
$('#DocumentInfoTable').html(...);
它会在每次调用时替换html内容。
尝试将其替换为:
$('#DocumentInfoTable').append(...);
你能发布你得到的实际json吗?我的猜测是,您没有得到json数组。