用jQuery / Javascript迭代彻底的JSON(Iterating thorough JSON with jQuery/Javascript)
我正在尝试使用JSON数据填充表格。 当我运行下面的脚本时,我只获得了最后一个条目10.我必须做某种.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>" ) }; }); }); });谢谢,
亚伦
I am trying to fill a table with JSON data. When I run the following script I get only the last entry of 10. I must have to do some sort of .append() or something. I've tried to put this in but it just returns nothing.
$(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>" ) }; }); }); });Thank you,
Aaron
最满意答案
您的代码具有以下内容:
$('#DocumentInfoTable').html(...);它会在您每次打电话时替换html内容。 尝试用以下代码替换它
$('#DocumentInfoTable').append(...);Your code has the following:
$('#DocumentInfoTable').html(...);which replaces the html content every time you call it. Try replacing that with:
$('#DocumentInfoTable').append(...);更多推荐
发布评论