2016-04-25 8 views
0

私のオブジェクトにはsumPriceというオブジェクトがあり、キーの値に応じて表示したいと思っています。ただし、キーはgrpの実際の値と同じでなければなりません。JavaScript node.jsのpug(jade)テンプレートの動的オブジェクトキー

私はケースsumPrice.grp、「sumPrice.grp」ではなく「sumPrice.Fruit」用のアプリケーションを検索値に仮定

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

下記より良い説明します - GRPが可変であることを認識しません。このための簡単な解決策はありますか?

答えて

1

sumPrice.grpsumPriceにはgrpという名前のキーがないため、機能しません。

sumPrice[grp]を使用するとできます。

この場合、名前ではなくgrpの値を使用します。

+0

私は試してみました: 'th = sumSales。[grp]'、私はドットを削除するのを忘れました... – DiPix

関連する問題