遇到的环境:
this.state=({
key:1,
funcTree:null,
checkedKeys:[],
searchCard:{
searchCard:"",,
cardKey:0,
selectedKey:"",
expandKeys:[],
},
drawer:{
drawerKey:1,
isShow:false,
data:[1,2,3]
}
});
上面的state中包含了多层的数据结构,当你在试图用如下方法改变子结构的时候,例:
this.setState({
drawer:{
isShow:true
}
});
它会使drawer下其他属性丢失。
解决的方案:
this.state.drawer.isShow = true;
this.setState(
this.state
);
这样同时保留了其他的属性。