javascript - 如何在 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})}
/>
我希望能够设置state
my checkbox
,但我无法完成。
我正在使用FlatList
,当我渲染我的应用程序时,这renderRooms
给了我 2 个列表。我认为问题在于这两个列表应该有自己的状态。但我不知道该怎么做。
寻找一些帮助。预先感谢。
解决方案
推荐阅读
- html - 卡片布局中的内容在移动视图中不会缩小
- java - 多个 Spring @RequestMapping 标头
- javascript - 在 Eclipse Photon 中使用 async/await 验证错误
- c# - 三层c#asp.net数据库应用中OOP的正确使用
- spring-boot - Spring Boot 嵌入式 TomCat 添加执行器后无法启动
- amazon-cloudformation - 在 Cloudformation 中创建 Application Load Balancer 时出错... XXXXX 必须是 ARN 格式
- javascript - 数组内容未在 ReactJS 中呈现
- c# - 在c#中打破骆驼案例功能
- swift - 如果通过 selectedIndex 属性进行更改,则更改视图时的动画将无法正常工作
- python - Python:用项目列表替换列表中的项目