reactjs - How can I use two component with map in react-native
问题描述
I want to use two component Text and Radiobutton with map. Like this..
please help me!
{Object.keys(temp_data).map(room => (
<Text> {room} </Text>
<RadioForm
radio_props={radio_props}
initial={0}
buttonColor={'#2196f3'}
animation={true}
onPress={(value) => {this.setState({value:value})}}
/>
))
}
解决方案
您可以使用fragment
{Object.keys(temp_data).map(room => (
<React.Fragment>
<Text> {room} </Text>
<RadioForm
radio_props={radio_props}
initial={0}
buttonColor={'#2196f3'}
animation={true}
onPress={(value) => {this.setState({value:value})}}
/>
</React.Fragment>
))
}
或者
{Object.keys(temp_data).map(room => (
<>
<Text> {room} </Text>
<RadioForm
radio_props={radio_props}
initial={0}
buttonColor={'#2196f3'}
animation={true}
onPress={(value) => {this.setState({value:value})}}
/>
</>
))
}
我认为这种方式更清洁
推荐阅读
- r - 直接从 Kaggle 将 CSV 数据集加载到 R 中
- c# - 使用 c# 和 MVC 将使用递归的字符串路径目录结构转换为 JSON 对象
- qt - QML 中的 QMap 数据类型
- java - 将第三个按钮添加到 JOptionPane 下拉菜单
- sql - 查找所有卡号,其中最大的 id oracle
- node.js - Plesk Obsidian - docker 域代理不工作
- r - R中的基因表达谱图
- spring-boot - 在 Spring Boot 测试中重用昂贵的 bean
- html - CSS Flexbox - 如何使父 div 成为嵌套子 img 的高度
- c# - 导航失败。无法找到 ModernTab WPF 的资源