你的
requests
数组应该具有在将其传递给时需要解决的所有承诺
$q.all
.目前,您正在添加您的承诺
loadEpisodes
到
请求
您可以将其分解,以便内部部分返回自己的部分
$.q.all
var requests = [];
series.forEach(function (seriesId) {
requests.push(loadSeriesDetails(seriesId).then(function (data) {
console.log("received details for series " + seriesId);
return data;
}));
requests.push(loadSeasons(seriesId).then(function (data) {
console.log("received seasons for series " + seriesId + ": ", data.seasons.length);
return loadAllEpisodes(data.seasons);
}));
});
function loadAllEpisodes(seasons) {
var requests = seasons.map(function (season) {
return loadEpisodes(season.id).then(function (data) {
console.log("received episodes for season " + season.id + ": ", data.episodes.length);
return data;
});
});
return $q.all(requests);
}
q.all(requests).then(function(result) {
console.log("*** all requests completed ***");
console.log(result.length);
});
$q.all
,因为你正在从每条链的最后承诺中获得结果。因此,您可能需要调整返回语句,使其按您需要的方式对信息进行分组。