情况:用户希望使用Youtube的JSON API在JQuery网站中导入Youtube播放列表。JQuery:合并多个JSON结果
问题: Youtube仅返回前50条目,但播放列表可能有100条以上的条目(长度由JSON响应中的'totalItems'给出)。所有条目都需要合并为1个对象,并且最后需要将其输入到输出函数中。
当前代码:
function fetchPlaylist(pid) {
var the_url = 'http://gdata.youtube.com/feeds/api/playlists/' + encodeURIComponent(pid) + '?v=2&alt=jsonc&max-results=50';
$.ajax({
type: "GET",
url: the_url,
dataType: "jsonp",
success: function (responseData, textStatus, XMLHttpRequest) {
if (responseData.data != null) {
if (responseData.data.items) {
outputFunction(responseData.data.items);
} else {
console.log('No results for playlist: "' + pid + '"');
}
}
}
});
}
问:
在收到所有条目之前,重复JSON调用的最有效方式是什么?
如何将不同的响应组合成一个对象?
我已经试过什么:
与使用http://api.jquery.com/jQuery.extend/合并,卡住了,因为复杂/嵌套情况
对于合并,'$。extend()'有一个深层复制选项,例如:'$ .extend(true,results,newResultsToAdd);' – 2010-10-04 16:42:09