繁体   English   中英

JavaScript node.js中的pug(jade)模板处的动态对象密钥

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM