Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/453.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在Pug中定义内联变量_Javascript_Node.js_Express_Pug - Fatal编程技术网

Javascript 如何在Pug中定义内联变量

Javascript 如何在Pug中定义内联变量,javascript,node.js,express,pug,Javascript,Node.js,Express,Pug,我正在使用节点+快捷应用程序的Pug模板引擎 我需要在哈巴狗档案里计算一下。例如,我有一个object数组,我必须打印所有object的amount字段的和,并且需要在表中显示所有amount 为此,我使用了Pug中可用的每个循环 我试着这样做: div each discount in el.Discounts if trxn.category != category var discountAmount = discount.amount * -1

我正在使用节点+快捷应用程序的Pug模板引擎

我需要在哈巴狗档案里计算一下。例如,我有一个object数组,我必须打印所有object的amount字段的和,并且需要在
表中显示所有amount

为此,我使用了Pug中可用的
每个
循环

我试着这样做:

   div
    each discount in el.Discounts
     if trxn.category != category
      var discountAmount = discount.amount * -1
      var distTotal = distTotal + discount.amount
      p= distTotal
但它不起作用,我想声明并更新内联变量

我怎样才能做到这一点


谢谢。

在var前面,你应该写“-”


什么是
p
?您得到的输出是什么?你在期待什么?请分享一些数据。P是HTML的段落标记。我没有得到任何错误,但也没有得到结果。
p
不应该在if语句之外吗?并且只需在每个迭代器之前将discountAmount和distTotal定义为0;
div
    each discount in el.Discounts
     if trxn.category != category
      - var discountAmount = discount.amount * -1
      - var distTotal = distTotal + discount.amount
      p= distTotal