reactjs - 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>
);
})}
解决方案
你错过了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>
);
})}
推荐阅读
- python - 如何使用 Word2Vec 进行预测?
- java - Spring Batch 中远程分区的性能问题
- html - 如何使用 VBA 代码将 .html 文件转换为现有的 .xlsm 文件?
- sql-server - 在 SQL Server 2017 或 SQL Server 2019 中是否支持始终使用事务复制进行加密?
- python - 不能将 attach_mock 与 autospec 函数模拟一起使用
- c - 从C中的fifo清除fread()上的缓冲区?
- c# - 数据模板中的按钮无法识别命令
- r - 我可以在不使用 merge() 函数的情况下对 data.table 执行此操作吗?
- javascript - 如何在旧版浏览器中隐藏 JavaScript?
- spring-webflux - 如何使用项目反应器同步刷新访问令牌