当我点击1个checkbox时,所有的values checkbox也都被选中了,那么我的问题是如何根据数组的值将它分开?
render () {
const { data } = this.props
const { checked, statusChecked, unhide } = this.state
const checkBoxCourier = data.map((item, index) => {
return (
<Card key={index} style={globalStyle.padDefault}>
<Item>
<Text>
{'[LOGO] '}
</Text>
<Text style={styles.bold}>{item.courier_name.toUpperCase()}</Text>
</Item>
{
item.services.map((item2, index) => (
<ListItem
key={index}
>
<CheckBox
checked={checked}
onPress={() => this.onCheckBoxPress(item2.courier_service_id, item2.status)}
/>
<View style={styles.row}>
<Body>
<Text style={styles.textStyle}>{item2.service_name}</Text>
<Text style={styles.textStyle}>{item2.service_description}</Text>
</Body>
</View>
</ListItem>
))
}
</Card>
)
})
return (
<Container>
<ScrollView>
{checkBoxCourier}
</ScrollView>
</Container>
)
最佳答案
你这样做
checked={index+item2.courier_service_id == this.state.Selected ? checked :uncheck}
onPress={() => this.onCheckBoxPress(item2,index)}
/>
和 onCheckBoxPress
onCheckBoxPress(){
this.setState({Selected:index+item2.courier_service_id})
}
希望这对你有帮助
关于android - 如何将数组放入复选框并根据数组 id 单击它以 react native ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56250498/