问题描述
如果条件在ReactJS中不起作用。我想创建一个手风琴并从Excel工作表中获取数据。并设置ID的哪个数据显示哪个按钮,如果条件我将无法创建。
let total = pieces * weight;
console.log(total);
这是我的密码和框:https://codesandbox.io/s/hungry-bardeen-8m2gh?file=/src/App.js
解决方法
您可以使用ternary operator来检查if-else
语句。
按如下所示修改代码部分,
更改
{products.map((c) =>
(
if(c.ID === 1) { <--- this if condition is not working
<tr key={c.ID}>
<td>{c.ArticleNo}</td>
<td>{c.ProductName}</td>
<td>{c.Quantity}</td>
<td>{c.Price}</td>
<td>{c.TotalAmount}</td>
</tr>
}
))};
收件人:
{products.map((c) =>
c.ID === 1 ? (
<tr key={c.ID}>
<td>{c.ArticleNo}</td>
<td>{c.ProductName}</td>
<td>{c.Quantity}</td>
<td>{c.Price}</td>
<td>{c.TotalAmount}</td>
</tr>
) : null
)}
叉状沙箱: