reactjs - 渲染多个内部地图反应原生
问题描述
我无法在地图内渲染多个开关。
我有一个看起来像这样的数组:
array: [
{
"title": "test1"
},
{
"title": "test2"
}
]
然后在渲染和返回中,我使用地图并希望显示 2 个开关:
{this.state.array.map((item, index) => (
<View key={index}>
<Switch
trackColor={{ false: "#767577", true: "#81b0ff" }}
thumbColor={isEnabled ? "#f5dd4b" : "#f4f3f4"}
ios_backgroundColor="#3e3e3e"
onValueChange={toggleSwitch}
value={isEnabled}
/>
</View>
))}
每个开关的“isEnable”都必须是唯一的,我不知道这样做的最佳实践?
解决方案
array: [
{
"title": "test1",
isEnabled:false,
},
{
"title": "test2"
isEnabled:true,
}
]
{this.state.array.map((item, index) => (
<View key={index}>
<Switch
trackColor={{ false: "#767577", true: "#81b0ff" }}
thumbColor={item.isEnabled ? "#f5dd4b" : "#f4f3f4"}
ios_backgroundColor="#3e3e3e"
onValueChange={toggleSwitch}
value={item.isEnabled}
/>
</View>
))}
推荐阅读
- php - 根据不同的按钮提交动态获取数据
- python - 重新发生事件的概率
- c++ - GCC/Clang 不会生成临时对象
- javascript - 怎么做简单
没有工作 在 AngularJS 材料中? - c++ - 当元素数> 1000时,如何制作向量的笛卡尔积?
- python - python生成的我的SQL语法有什么问题?
- reactjs - 从 tsx 文件中的 controllerApi 方法检索数据 [Module Parse failed 错误]
- java - 在 Google Cloud Storage 中创建存储桶有时会失败
- javascript - Stripe - PaymentIntents handleCardPayment() - 如何捕捉 JS 错误?
- vue.js - vuejs:从子dataAttr调用父函数