我的视图上有对象sumPrice
,我想显示依赖于键的值。但密钥必须与grp
的实际值相同。
我会在下面更好地解释
- each grp in Object.keys(groupedData)
h3= grp // for example grp has value Fruit
table
thead
th Name
th Price
tfoot
th Sum:
th= sumPrice.grp //this doesn't work, but this: th= sumPrice.Fruit will work!
th
th
tbody
// [........]
我想在sumPrice.grp
的情况下,应用程序搜索值为"sumPrice.grp"而不是"sumPrice.Fruit" - 不识别grp是可变的。有没有简单的解决方案?
sumPrice.grp
不起作用,因为sumPrice
没有名为grp
的键。
您可以使用 sumPrice[grp]
.
在本例中,您将使用 grp
的值,而不是它的名称。