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

标签 android ios react-native

当我点击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/

相关文章:

javascript - 如何更改多个按钮中按下颜色的按钮 React Native

react-native - 使用 wix react native navigation v3 设置 react native 推送通知 - 应用程序关闭时出现问题

android - JSONException:索引 5 超出范围 [0..5)

ios - Storyboard中的 Xamarin iOS 启动屏幕图像未从 Assets 目录中提取

android - 在 Focus React Native Paper 上更改 TextInput 样式

ios - 如何在 iOS 的 webView 中设置适合的内容?

ios - 错误 : generic parameter 'T' could not be inferred in swift

android - 广播接收器、AIDL 和 Messenger 之间有什么区别?

android - gradle 构建工具版本从 1.2.3 升级到 1.3.1 的问题

android - 根上的 Firebase 引用查询