是否可以在循环中执行条件?我想打印我的对象数组,(例如:订单 = [ {id:000,delivery_date:1/10/2019,纸杯蛋糕:[香草,巧克力,草莓]},...])但我只想打印后端数据库中的那些(在单独的服务器上运行)并且最近提交(日期> =订单.交付日期)
有没有办法做到这一点?
renderTableData(orders) {
const date = new Date();
return (
<tbody>
{orders && orders.filter(order => date => new Date(order.delivery_date)).map(item =>
//CONDITIONAL HERE?
<tr key={item.id}>
<td>{new Date(item.delivery_date).toLocaleDateString()}</td>
<td>
{item.cupcakes.map((subitem =>
<ul>
<li>{subitem.base}</li>
<li>{subitem.frosting}</li>
<li>{subitem.toppings}</li>
</ul>
))}
</td>
</tr>
)}
</tbody>
);
}