I am trying to create a filter search for my company's CMS list of articles. I am not sure how to turn the returning JSON data into data for my html table. I have, however, not done this before and am not sure how to iterate through the data.
Here is some dummy output data:
[{"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"}]
Here is the relevant JS code:
$.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);
});
I already tried doing this using data[i].articleID but that didn't work for me either.
console.log(data);give you a string or an array.