如何在 React 中渲染嵌套数组元素?

How to render nested array elements in React?

我想渲染嵌套数组元素。为了渲染元素,我使用了 .map 但它不适用于第二个数组。

Using list=[{value: 'One', list:[{value: 'abc', selected: false}, {value: 'efg', selected: false}]}, {value: 'Two', list: [{value: 'psr', selected: false}]}];

   list.map((item, index) => {
        return (
          <div key={index}>
            <ul >{item.value}</ul>
            item.list.map((subitem, i) => {
              return (
                 <ul >{subitem.value}</ul>
              )
            })
          </div>
        )
      })

我遗漏了什么吗?

谢谢

试试这个。在第二个 map

之前,您错过了 { }
 list.map((item, index) => {
            return (
              <div key={index}>
                <ul >{item.value}</ul>
               {
                item.list.map((subitem, i) => {
                  return (
                     <ul ><li>{subitem.value}</li></ul>
                  )
                })
               }
              </div>
            )
          }

演示:https://jsfiddle.net/jwm6k66c/2611/