以下代碼在最後一個處理程序中解析爲Promise {[[PromiseStatus]]: "pending", [[PromiseValue]]: undefined}
。Promise.all()方法未解析爲值
雖然在向控制檯發送承諾時錄製陣列時,每個都有狀態resolved
,並且所有請求都得到滿足。
MusicService
.getArtists()
.then((res) => {
let arr = res.filter((a) => {
return a.id.length;
});
return Promise.all(arr.map(function(a) {
return fetch(`//service.com/api/artist/${a.id}`);
}));
})
.then((res) => {
console.log(res);
});
那麼,我錯過了什麼讓這個工作?
如果你在任何'then's中有一個失敗回調會發生什麼?還是一個'catch'? – Neal
@NielsSteenbeek承諾是如何工作的。在一個承諾中,你可以返回一個承諾,並將它鏈接在承諾鏈中。 – Neal
「以下代碼在最後一次處理程序中解析爲'Promise {[[PromiseStatus]]:」pending「,[[PromiseValue]]:undefined}'。是的,你期望什麼? –