【发布时间】:2017-11-10 18:59:50
【问题描述】:
我有以下减速器:
const ListingReducer = (state={
fetched:false
},action) => {
if ( action.payload )
{
console.log("action.token",action.token);
console.log("action.payload.profiles",action.payload.profiles);
}
switch(action.type)
{
case 'SET_LISTING_DATA':
state = {
...state,
[action.token] : action.payload,
fetched : true
}
break;
case 'APPEND_LISTING_DATA':
// console.log("Previous state was: "state[action.token]);
state[action.token]
= {
...state[action.token],
profiles : [...state[action.token].profiles,...action.payload.profiles],
fetched : true
}
// console.log("Next state is: "+state[action.token]);
break;
}
return state;
}
动作:
- SET_LISTING_DATA:它将数据设置到键
action.token,其中有一个名为profiles的键。 - APPEND_LISTING_DATA:它将数据附加到状态键
profile。
我可以在配置文件键中看到添加的配置文件,但它不会更新视图。
个人资料位于:
state[action.token] ={name:y,data:xy,profiles:[id:x,{},{}],...}
【问题讨论】:
标签: javascript reactjs redux reducers