【问题标题】:Iterating thorough JSON with jQuery/Javascript使用 jQuery/Javascript 遍历 JSON
【发布时间】:2010-03-29 20:05:02
【问题描述】:

我正在尝试用 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>"
        )
      };
    });
  });
});

谢谢,

亚伦

【问题讨论】:

  • 您能发布您返回的实际 json 吗?我的猜测是你没有得到一个 json 数组。

标签: javascript jquery json


【解决方案1】:

您的代码具有以下内容:

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

每次调用它都会替换 html 内容。 尝试将其替换为:

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

【讨论】:

    猜你喜欢
    • 2015-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多