javascript - 如何在 React.js 中使用重复循环
问题描述
如何在 React.js 中使用重复循环?
我有数组中的数组,我想使用它。
我有一个数组。对象在数组中。另一个数组在这些对象中。
state = {
myInformation: [
{
name: "jessie",
age: 27,
interests: ["react", "vue"]
},
{
name: "ellie",
age: 26,
interests: ["java", "spring"]
}
]
}
...
const information = this.state.myInformation.map(
({name, age, interests}) => (
<div>{name}</div>
<div>{age}</div>
<div>{interests}</div>
)
)
...
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
解决方案
在里面使用另一个map()。
const information = this.state.myInformation.map(
({name, age, interests}) => (
<div>{name}</div>
<div>{age}</div>
<div>{interests.map(interest => <div>{interest}</div>)}</div>
)
)
推荐阅读
- python - matplotlib 堆积条形图在版本更新后被窃听
- asp.net - EF Core 5 删除 HiLo 序列
- css - CSS网格自动填充总是两列
- c# - 一页中有两个本地视图 - 如何实现这一点?可见导航
- bots - MMORPG服务器的bot检测方法
- pandas - 如何按计数和条件查询
- sql - 有没有一种方法可以简单地转置 SQL 中的表。此表包含 Numeric 和 Varchar 值
- javascript - Javascript 单页应用程序 - Azure 部署 VS 代码
- javascript - 查找一个术语是否包含在对象数组中的对象值中
- selenium - 在以下场景中需要帮助以查找基于 webtable 的元素的 xpath