用jQuery / Javascript迭代彻底的JSON(Iterating thorough JSON with jQuery/Javascript)

编程入门 行业动态 更新时间:2024-10-24 03:25:23
用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(...);

更多推荐

本文发布于:2023-07-31 00:30:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1340465.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:迭代   Javascript   jQuery   JSON   Iterating

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!