当我点击1个复选框时,所有的值复选框也被选中,那么我的问题是如何根据数组的值来分隔它?
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>
)
发布于 2019-05-22 15:11:18
你是这样做的
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})
}
我希望这能对你有所帮助
发布于 2019-05-22 15:09:11
您需要向特定于服务项目而不是组件的复选框传递一个标志,如下所示:
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={item2.isChecked} // Save the value here
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>
)
})
https://stackoverflow.com/questions/56250498
复制相似问题