开发者

Iterating thorough JSON with jQuery/Javascript

开发者 https://www.devze.com 2022-12-25 04:35 出处:网络
I am trying to fill a table 开发者_如何学Cwith 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 i

I am trying to fill a table 开发者_如何学Cwith 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


Your code has the following:

$('#DocumentInfoTable').html(...);

which replaces the html content every time you call it. Try replacing that with:

$('#DocumentInfoTable').append(...);
0

精彩评论

暂无评论...
验证码 换一张
取 消