我正在使用 ajax 和 json 渲染页面。我的 json 结构是{"status":"ok","rewards":[{"id":201,"points":500},{"id":202,"points":500}]
如果“点”在任何散列中重复,我如何使 ajax 加载数据仅一次?
例如,我有很少散列的 json,其中“点”具有相同的值这是我的代码
$("#page").live('pagecreate', function(e) {
var request = $.ajax({
type: "GET",
url: "example.com/file.json",
dataType: "json",
error: function (data, tex
tStatus){
console.log( status );
console.log( data );},
success: function (data, textStatus){
console.log( "success" );
console.log( status );
console.log( data );
}
})
request.success(function(data, textStatus){
var lis = "";
var seen = {};
$.each(data.rewards, function(key, val){
lis += "<div class = 'reward-ui ui-block-" + String.fromCharCode(97 + key%3) + "'><a href ='#' class ='ui-link-inherit'>" + val.points + "</a></div>";
});
$(".ui-grid-b").html(lis);
});
//$('.even-odd').listview('refresh');
})
});