以下是我的默认状态
const defaultState = {
targetFilters: [
{
key:'Web version',
type:'RANGE',
uBound:'',
lBound:'',
tKey:'appBar.shopFilters.webVersion.name',
tInfo:'appBar.shopFilters.webVersion.info',
},
{
key:'Job status',
type:'SELECT&RANGE',
selections: ['Success','Unreachable'],
uBound:'',
lBound:'',
sIdx:0,
tSelections: ['dashboard.view.job.success.name','dashboard.view.job.unreachable.name'],
colors:['#388e3c','#FF9F00'],
tKey:'appBar.shopFilters.jobStatus.name',
tInfo:'appBar.shopFilters.jobStatus.info',
},
];
但是我观察到默认状态已更改。我知道是因为我在更新功能中将其打印出来,然后发现
颜色:['#388e3c','#FF9F00']
通常更改为
颜色:['#388e3c']
export function updateShopFiltersState(state=defaultState,action){console.log(defaultState);
switch(action.type) {
...
default:
return state;
}
}
我真的很困惑,不知道为什么。欢迎任何建议
答案 0 :(得分:0)
非常感谢。 可能的根本原因可能是,当我使用“颜色”时,像下面这样使用“参考”颜色,
const {shopFiltersState} =store.getState();
let cur=shopFiltersState.targetFilters.find((f)=>{return f.key==='Job status'}),
chartConfig={
colors: cur?(cur.colors):[], //directly use the colors reference; this line may be problematic
},
不幸的是,以后的引用修改可能会导致直接写入数组,因此我将写入更改为
colors: cur?copy(cur.colors):[]