【发布时间】:2017-04-03 00:24:48
【问题描述】:
我有一个这样的数组
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而不是修改后的数组。我想调度发送新的修改数组。而且我认为应该是,不是吗?
【问题讨论】:
标签: javascript promise redux redux-thunk