我需要加一个购物篮的总数,但我不知道如何使用玉来做到这一点
以下是我认为我可以实现它但它不起作用的方式,我试过的其他方法只是继续抛出错误.
有谁知道我会怎么做?
each item in bagItems
- var total = total + item.realprice
p= total
Run Code Online (Sandbox Code Playgroud)
使用阵列上的reduce方法应该很容易.
p= bagItems.reduce(function(total, item) { return total + item.realprice; }, 0)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2102 次 |
| 最近记录: |