我需要计算一个购物篮的总数,但我不知道如何使用 jade 来做这件事
这是我认为我可以实现它的方法,但它不起作用,我尝试过的其他方法只是不断抛出错误。
有人知道我会怎么做吗?
each item in bagItems
- var total = total + item.realprice
p= total
最佳答案
使用数组上的 reduce 方法应该很容易做到这一点。
p= bagItems.reduce(function(total, item) { return total + item.realprice; }, 0)
关于node.js - 使用 jade 模板引擎加总,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9982334/