我有这个代码:
$('#find').click(function(){
if(first.val() != '' && second.val() != ''){
$.getJSON(urlPersonSearch + first.val() + "?callback=?", function(json) {
firstId = (json[0].id != undefined) ? json[0].id : '';
if(firstId != '') result = grabMovies(firstId);
var i = result[0].filmography.length;
while(i--){
movies[result[0].filmography[i].id] = result[0].filmography[i].name;
}
});
$.getJSON(urlPersonSearch + second.val() + "?callback=?", function(json) {
secondId = (json[0].id != undefined) ? json[0].id : '';
if(secondId != '') result = grabMovies(secondId);
var i = result[0].filmography.length;
while(i--){
movies[result[0].filmography[i].id] = result[0].filmography[i].name;
}
});
}
});
function grabMovies(id){
$.getJSON(urlPersonResult + id + "?callback=?", function(json) {
return json;
});
}
现在,我想要做的是最终得到一个以 ID 和电影名称作为键/值的对象。最终,我试图获得一个仅包含两个 json 结果之间匹配项的对象。IE。
如果第一个结果是
23 = 你好,283 = 再见,
第二个的结果是
23 = 你好,294 = 再见
我最终会得到一个对象
23 = 你好
有没有人对如何做到这一点有任何建议?