首页 > 解决方案 > JSX map里面有一个map可以吗?

问题描述

我正在尝试在 JSX 中映射一个地图,但第二个内部地图没有呈现为什么?

        {food.map((item: ItemsShape, index: number) => {
          return (
            <div key={`${index}`}>
              <div>{item.Quantity}</div>
              <div>{item.Name}</div>
              {item.Options && <div>{JSON.stringify(item.Options)}</div>} // <= this shows al the options
              {item.Options &&
                item.Options.map((option: any) => {
                  <div>OPTION {option.Name}</div>;
                })} // <= This doesnt even render why?
            </div>
          );
        })}

标签: reactjs

解决方案


你错过了return

    {food.map((item: ItemsShape, index: number) => {
      return (
        <div key={`${index}`}>
          <div>{item.Quantity}</div>
          <div>{item.Name}</div>
          {item.Options && <div>{JSON.stringify(item.Options)}</div>} // <= this shows al the options
          {item.Options &&
            item.Options.map((option: any) => {
              return (<div>OPTION {option.Name}</div>);
            })}
        </div>
      );
    })}

推荐阅读