【发布时间】:2017-07-29 16:42:19
【问题描述】:
我映射多个对象。
[{name:"y", country:"US", cities:[obj,obj,ob]},{name:"y", country:"US", cities:[obj,obj,ob]}]
如何嵌套循环,以便首先遍历对象,然后遍历(在此示例中)城市?谢谢!!
没有嵌套外观的渲染函数如下所示:
render() {
const persons = this.state.name.map((item, i) => {
return (
<div>
<h5> {item.name} </h5>
<h5> {item.country} </h5>
//here I would like to show the cities
</div>
);
});
return (
<div>
<div className = "panel-list">
All: {persons}
</div>
</div>
);
}
城市对象示例:
[{visitors:34, rating:4},
{visitors:1234, rating:1},
{visitors:124, rating:2}]
【问题讨论】:
标签: javascript reactjs loops