react checkbox無法選中 但是state已經發生變化


因為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必須要重新繪制整個組件才會生效
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM