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