我有要从JSON显示的表格
<th>
{
x.amountForQuantity.filter((remaining) => {
return remaining.hasOwnProperty(cost.key);
})[cost.key]
}
</th>上面的标记返回空,我在这里做错了什么?
沙盒link
发布于 2021-04-15 17:36:47
您的数组结构如下所示
const row = [
...
amountForQuantity: [
{
key: "Labour Cost",
value: 150
},
{
key: "Material Cost",
value: 570
}]
...
];因此,cost.key不是对象的属性,而是key属性的value。
所以你的代码应该是这样的。
x.amountForQuantity.filter((remaining) => remaining.key == cost.key)[0].valuehttps://stackoverflow.com/questions/67105779
复制相似问题