我正在尝试为我公司的 CMS 文章列表创建过滤器搜索。我不确定如何将返回的 JSON 数据转换为我的 html 表的数据。但是,我以前没有这样做过,并且不确定如何遍历数据。
这是一些虚拟输出数据:
[{"articleID":"7298","title":"inbrief","issueDate":"July 2012"},{"articleID":"7299","title":"inbrief","issueDate":"July 2012"},{"articleID":"7300","title":"inbrief","issueDate":"July 2012"},{"articleID":"7301","title":"inbrief","issueDate":"July 2012"}]
这是相关的JS代码:
$.post("link", { issue: isearch, availability: asearch, type: tsearch }, function(data) {
var htm =''
console.log(data);
for(var i=0; i<data.length; i++)
{
jason = data.getJSONObject(i);
articleID = jason.articleID;
title = jason.title;
issueDate = jason.issueDate;
htm += '<tr id="news'+articleID+'">'
+ '<td>'+title+'</td>'
+ '<td>'+issueDate+'</td>'
+ '<td><a href="cms/index/addnews/news/'+articleID+'">make top news</a></td>'
+ '<td><a href="link">view</a></td>'
+ '<td><a href="cms/news/updatenews/'+articleID+'">update</a></td><td><a href="" class="delete" id="'+articleID+'">delete</a></td>'
+ '</tr>';
}
$('.cms').html(htm);
});
我已经尝试使用 data[i].articleID 执行此操作,但这对我也不起作用。