Javascript 使用Map解析列表项的正确方法是什么?

Javascript 使用Map解析列表项的正确方法是什么?,javascript,reactjs,Javascript,Reactjs,我在分析道具时遇到以下错误: 无法读取未定义的属性“map” 在道具props.doubleArray中。但是,当我打印它时,它会在控制台中显示一个双数组。使用地图的正确方法是什么 class Menu extends Component { render() { return ( <div className="menu__row"> <ListItems doubleArray={[

我在分析道具时遇到以下错误:

无法读取未定义的属性“map”

在道具
props.doubleArray
中。但是,当我打印它时,它会在控制台中显示一个双数组。使用地图的正确方法是什么

class Menu extends Component {

render() {
return (
<div className="menu__row">
            <ListItems
              doubleArray={[
                [
                  "New & Featured",
                  "Shop All New Arrivals",
                  "SNKRS Launch Calendar",
                  "Best of Air Max",
                  "Member Access",
                ],
                [
                  "New & Featured",
                  "Shop All New Arrivals",
                  "SNKRS Launch Calendar",
                  "Best of Air Max",
                  "Member Access",
                ],
                [
                  "New & Featured",
                  "Shop All New Arrivals",
                  "SNKRS Launch Calendar",
                  "Best of Air Max",
                  "Member Access",
                ],
                [
                  "New & Featured",
                  "Shop All New Arrivals",
                  "SNKRS Launch Calendar",
                  "Best of Air Max",
                  "Member Access",
                ],
              ]}
            />
            <ListItems />
          </div>

);
}
}

function ListItems(props) {
  return (
<div className="listItems">
  {props.doubleArray.map((array) => (
    <ul className="listItems__column" key={array.id} value={array}>
      <li className="listItems__title"> {array[0]}</li>
      {array.map((item, index) =>
        index > 0 ? (
          <li className="listItems__text" key={item.id} value={item}>
            {item}
          </li>
        ) : null
      )}
    </ul>
  ))}
</div>
  );
}

export default Menu;
类菜单扩展组件{
render(){
返回(
);
}
}
功能列表项(道具){
返回(
{props.doubleArray.map((数组)=>(
  • {array[0]}
  • {array.map((项,索引)=> 索引>0(
  • {item}
  • ):null )}
))} ); } 导出默认菜单;
试试这个:

<div className="listItems">
  {props.doubleArray && props.doubleArray.map((array) => (
    <ul className="listItems__column" key={array.id} value={array}>
      <li className="listItems__title"> {array[0]}</li>
      {array.map((item, index) =>
        index > 0 ? (
          <li className="listItems__text" key={item.id} value={item}>
            {item}
          </li>
        ) : null
      )}
    </ul>
  ))}
</div>

{props.doubleArray&&props.doubleArray.map((数组)=>(
  • {array[0]}
  • {array.map((项,索引)=> 索引>0(
  • {item}
  • ):null )}
))}
不要在帖子中添加垃圾文本来回避要求您详细解释问题的要求-相反,请实际更详细地解释问题,例如您尝试过的哪种调试不起作用。看看如何创建一个与问题不直接相关的修剪代码也很有帮助。请访问这个,看看它是什么和奇怪。我的评论在这里被删除了。& &首先验证并查看列表是否存在,然后解析项目。映射仅存在于项目列表(即元素数组)上。希望这能回答你的疑问。