使用玉模板引擎加总

jam*_*upe 2 node.js pug

我需要加一个购物篮的总数,但我不知道如何使用玉来做到这一点

以下是我认为我可以实现它但它不起作用的方式,我试过的其他方法只是继续抛出错误.

有谁知道我会怎么做?

each item in bagItems
    - var total = total + item.realprice
p= total
Run Code Online (Sandbox Code Playgroud)

Pre*_*aul 6

使用阵列上的reduce方法应该很容易.

p= bagItems.reduce(function(total, item) { return total + item.realprice; }, 0)
Run Code Online (Sandbox Code Playgroud)