因為checkbox是動態生成的,是react-native-table-component組件里面的一個元素,如果我只改變checkbox的state 不會生效,要改變整個table的state才可以
let aaa = [];
const index2 = index + 1;
aaa.push(<CheckBox
// checked={this.state[index]}
key={index}
name='secotr'
square={true}
style={{ color: 'rgb(231,231,231)' }}
// onPress={()=> {
// //this._onPress()
// this.setState({
// //[index]:!this.state[index]
// checked:true
// })
// }}
checked={val.checked}
onPress={(e) => this.toggleSwitch3(index, e)}
/>);
toggleSwitch3(index, e) {
console.log(e.target.checked, 'eeeeeeeeeeeeeeeeeeeeeeeeeee')
let sectorName="";
if (this.state.item && this.state.item.sectors) {
this.state.item.sectors.map((row, index1) => {
if (index1 == index) {
this.state.item.sectors[index1].checked = true;
sectorName = this.state.item.sectors[index].sectorName
} else {
this.state.item.sectors[index1].checked = false;
}
});
}
this.setState({
//[index]: !this.state[index],
SECTOR_ID: sectorName,
checked: true
});
this.updateSectors(this.state.item);
}
this.state.item里面存的就是table里面的tabledata
所以如果改變動態組件里面的state必須要重新繪制整個組件才會生效