我不认为我会调用它两次,但出于某种原因,我从我的 JSON 中获取了 5 个元素,显示了两次。这是Jquery。
$.getJSON('js/data.json', function(data) {
function rowBuilder(value) {
return '<tr>'
+ '<td>'
+ value.productList
+ '</td>'
+ '<td class="center">'
+ value.sales
+ '</td>'
+ '<td class="center">'
+ value.awards
+ '</td>'
+ '</tr>';
}
$.each(data.productRewards, function(k,v){
$('#details tbody').append(rowBuilder(v));
});
});
我的JSON如下:
{ "productRewards":[
{
"productList": "New Sales",
"sales": "25",
"awards": "500"
},
{
"productList": "TV",
"sales": "12",
"awards": "18"
},
{
"productList": "TV Completers",
"sales": "7",
"awards": "210"
},
{
"productList": "HSI Enhanced",
"sales": "15",
"awards": "150"
},
{
"productList": "MODULE",
"sales": "68",
"awards": "360"
}
]
}
它显示 10 个项目。任何帮助将不胜感激。