首页 > 解决方案 > 如何在 React Native 中选择 FlatList 项?

问题描述

我有这个代码:

renderRooms = ({item:room}) => {
  return(
    <View style={styles.cards}>
      <View style={styles.cardRight}>
        <View style={{ marginLeft:2, alignItems: 'center', flex:1 }}>
          <Text style={{fontSize:12, marginTop:10, marginBottom: 5, color:'#B0B0B0'}}>
             Harga/malam
          </Text>      
          <Text style={{fontSize:12, textDecorationLine:'line-through'}}>              
            {`${'Rp.'}${room.pricing.normal}`}
          </Text>
          <Text style={{fontSize:14, fontWeight:'800', color:'#26de81', }}>
            {`${'Rp.'}${room.pricing.discount}`}
          </Text>
          <CheckBox
            // center
            iconRight
            title={this.state.showContinueToPayment == true ? 'Batal' : 'Pilih'}                                                            
            checked={this.state.showContinueToPayment}
            containerStyle={{padding:5, borderColor:'white', backgroundColor:'white'}}
            onPress={() => this.setState({showContinueToPayment: !this.state.showContinueToPayment})}
          />
        </View>
      </View>
    </View>
  )
}


在这部分:

<CheckBox
  iconRight
  title={this.state.showContinueToPayment == true ? 'Batal' : 'Pilih'}                                                                                            
  checked={this.state.showContinueToPayment}
  containerStyle={{padding:5, borderColor:'white', backgroundColor:'white'}}
  onPress={() => this.setState({showContinueToPayment: !this.state.showContinueToPayment})}
/>

我希望能够设置statemy checkbox,但我无法完成。

我正在使用FlatList,当我渲染我的应用程序时,这renderRooms给了我 2 个列表。我认为问题在于这两个列表应该有自己的状态。但我不知道该怎么做。

寻找一些帮助。预先感谢。

标签: javascriptreact-native

解决方案


推荐阅读