[英]Dynamic object key at pug (jade) template in JavaScript node.js
我的视图上有对象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
的值而不是它的名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.