我的视图中有对象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是可变的。对此有什么简单的解决方案吗?
答案 0 :(得分:1)
sumPrice.grp
不起作用,因为sumPrice
没有名为grp
的密钥。
您可以使用sumPrice[grp]
来完成此操作。
在这种情况下,您将使用grp
的值,而不是它的名称。