【发布时间】:2020-02-26 18:50:22
【问题描述】:
我有一个带有几个项目的复选框,当我单击复选框时,该项目将添加到名为 currentDevice 的状态,但是当我取消选中该项目时,它会保留添加项目而不是删除它。
当我取消选中该框时,如何从状态中删除项目。我使用 react-native-element 复选框。之前谢谢你
代码:
constructor(props) {
super(props)
this.state = {
currentDevice: [],
checked: []
}
}
handleChange = (index, item) => {
let checked = [...this.state.checked];
checked[index] = !checked[index];
this.setState({ checked });
this.setState({currentDevice: [...this.state.currentDevice, item.bcakId]})
}
renderFlatListDevices = (item, index) => {
return (
<ScrollView>
<CheckBox
title={item.label || item.bcakId}
checked={this.state.checked[index]}
onPress={() => {this.handleChange(index, item)}}
checkedIcon='dot-circle-o'
uncheckedIcon='circle-o'
checkedColor='#FFE03A'
containerStyle={styles.containerCheckBox}
textStyle={styles.textCheckBox}
/>
</ScrollView>
)
}
【问题讨论】:
标签: javascript react-native checkbox