1
在此函數中,在內聯數組完成之前調用回調函數。我只能在內聯具有所有值時才能調用它?如何運行promise數組
function inlineSearch(search, callback) {
const inline = []
mal.quickSearch(search).then(response => {
response.anime.forEach(anime => {
anime.fetch().then(json => {
inline.push(replyInline(json))
})
})
.then(callback(inline))
})
}
response.anime
是一個JSON對象數組指向另一個JSON對象,這就是爲什麼我需要把它牽回家,所以我可以有正確的JSON。
而且,replyInline
是一個函數,它只接受json並返回另一個。
mal
=我的動漫列表API
你有沒有看着['Promise.all()'](https://開頭developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)? – nnnnnn
順便說一句,你需要'Promise.all'和'repsonse.anime.map' –
,最後'.then'保證是錯誤的,因爲'.then'需要一個函數作爲參數 –