我有一个 JSON 文件,其中正在读取对象并将它们显示在 div 中。但我只需要显示五个对象而不是全部。
下面是我正在使用的代码
$.each(recentActdata.slice(0,5), function(i, data) {
var ul_data = "<li><h3>"+ renderActionLink(data)+ "</h3></li>";
$("#recentActivities").append(ul_data);
});
但这片似乎不起作用。我的 JSON 格式是
[
{
"displayValue":"Updated Guidelines",
"link":"#",
"timestamp":"29/06/2013 01:32"
},
{
"displayValue":"Logging",
"link":"#",
"timestamp":"28/06/2013 16:19"
},
{
"displayValue":"Subscribe",
"link":"#",
"timestamp":"21/06/2013 14:30"
},
{
"displayValue":"Artifactory Vs Nexus",
"link":"#",
"timestamp":"21/06/2013 13:39"
},
{
"displayValue":"CTT - Java 7",
"link":"#",
"timestamp":"20/06/2013 13:30"
},
{
"displayValue":"Added Artifactory Server",
"link":"#",
"timestamp":"19/06/2013 23:39"
},
{
"displayValue":"Estimation Template",
"link":"#",
"timestamp":"19/06/2013 23:39"
},
{
"displayValue":"GZIP compression in Tomcat",
"link":"#",
"timestamp":"14/06/2013 23:39"
},
{
"displayValue":"HBase Basics",
"link":"#",
"timestamp":"12/06/2013 23:39"
}
]
请建议如何实现这一目标。我不能给我的 JSON 起个名字。