0
我使用休息API一次创建多个记录。 action.payload
包含从服务器返回的每个记录的id
。将id添加到我刚刚在reducer中创建的每条记录的最佳方法是什么?添加一个对象数组以在减速器中状态
这是我到目前为止。我没有收到任何错误,但这些记录在创建后并未出现在我的应用中。
const INITIAL_STATE = { all: [] };
export default function(state = INITIAL_STATE, action) {
case POST_TERRITORY_GEOGRAPHY_MASS:
let territories= action.territories.records;
action.payload.then(request => {
for(var i = 0; i < request.data.results.length; i++) {
territories[i].Id = request.data.results[i].id
}
return {
...state.all, territories
????
}
})
}
您能够在减速更新承诺的一部分then
内部状态?
如果我错了,请纠正我的错误:在该例中已使用'redux-thunk'中间件http://redux.js.org/docs/advanced/ExampleRedditAPI.html#configurestorejs – Vikram