Render a nested array of objects in react

后端 未结 1 1912
無奈伤痛
無奈伤痛 2020-12-18 16:28

I map through multiple objects. [{name:\"y\", country:\"US\", cities:[obj,obj,ob]},{name:\"y\", country:\"US\", cities:[obj,obj,ob]}]

How can I nest

1条回答
  •  误落风尘
    2020-12-18 17:04

    you can make use of nested map to map over the inner child obejcts as well like

         render() {
                const persons = this.state.name.map((item, i) => {
                    return (
                       
    {item.name}
    {item.country}

    {item.cities.map((city) => { return (
  • {/* city object details here*/}
  • ) })}

    ); }); return (
    All: {persons}
    ); }

    0 讨论(0)
提交回复
热议问题