我有像這樣的JavaScript - 終極版咚不等待任何承諾
array =[ {message:'http://about.com'}, {message:'http://facebook.com'}]
我想循環,數組的數組,在每個項目我會請求服務器獲取數據opengraph然後保存數據返回到數組。這是我期望的
array =[
{
message: { url:'http://about.com', title:'about'}
},
{
message:{ url:'http://facebook.com', title:'facebook'}
}
]
然後當這一切都完成。我想分配一個有效載荷的行動是預期的陣列。這是我怎麼做
return dispatch => {
let array =[ {message:'http://about.com'}, {message:'http://facebook.com'}]
let quests = array
.map((item) => {
axios.get(getOpenGraphOfThisLink + item.message)
.then(result =>{
item.message = (result.data)
return result
})
})
Promise.all(quests).then(() => {
console.log('modified', array)
dispatch({
type : constant.GET_POST_COLLECTION_SUCCESS,
payload: array
})
// this dispatch function sends my original array instead of modified one.
})
}
問題:代碼中的調度功能將我的原始數組發送到reducer而不是修改的。我想派遣發送新的修改後的數組。我認爲應該,不是嗎?
直截了當肯定的,但要注意在我的答案中有附帶條件。 –
我得到了類似的情況,任何想法如何解決http:// stackoverflow。com/questions/40791724/javascript-restorex-thunk-doesnt-wait-for-any-promise-again –