求教老师,数组对象属性改变了,checkBox 选中状态不更新,什么原因
来源:5-9 Popular(最热)模块的自定义标签功能实现-4

慕移动4626964
2018-03-29
onClick(data){
data.checked = !data.checked;
if (data.name === 'ALL' && data.checked ===true){
for (let i =0;i <this.state.keysArr.length;i++){
var key = this.state.keysArr[i];
key.checked = true;
key.name = 'xxxxxx'
}
this.forceUpdate();
}
}
我想点击ALL 把所有的标签都置为可选 ,上面写 只有名字变化了 check状态没有改变
写回答
2回答
-
CrazyCodeBoy
2018-03-30
getDerivedStateFromProps是react 16.3.0以上版本的新特性,用来代替componentwillreceiveprops,看一下你的react版本,react 16.3的一些用componentwillreceiveprops
00 -
CrazyCodeBoy
2018-03-29
断点调试一下看checkBox的
static getDerivedStateFromProps(nextProps, prevState) { if (prevState.isChecked !== nextProps.isChecked) { return { isChecked: nextProps.isChecked }; } return null; }
方法有没有被调用,https://github.com/crazycodeboy/react-native-check-box/blob/master/index.js
032018-03-29
相似问题