gpt4 book ai didi

javascript - JavaScript Node.js 中 pug (jade) 模板的动态对象键

转载 作者:行者123 更新时间:2023-12-03 07:05:17 26 4
gpt4 key购买 nike

我的 View 上有对象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 的值,而不是它的名称。

关于javascript - JavaScript Node.js 中 pug (jade) 模板的动态对象键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36849231/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com