2016-04-25 24 views
0

我在我的視圖上有對象sumPrice,我想顯示值取決於鍵。但關鍵必須與grp的實際值相同。JavaScript中的帕格(jade)模板的動態對象關鍵字node.js

我會更好地解釋如下

- 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是可變的。有沒有簡單的解決方案?

回答

1

sumPrice.grp不起作用,因爲sumPrice沒有名爲grp的密鑰。

您可以使用sumPrice[grp]

在這種情況下,您將使用的值爲grp而不是名稱。

+0

太棒了,我試過了:'th = sumSales。[grp]',我忘了刪除點... – DiPix

相關問題