gpt4 book ai didi

android - 如何将数组放入复选框并根据数组 id 单击它以 react native ?

转载 作者:行者123 更新时间:2023-11-28 23:31:38 24 4
gpt4 key购买 nike

当我点击1个checkbox时,所有的values checkbox也都被选中了,那么我的问题是如何根据数组的值将它分开?

enter image description here

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com