我想对使用 JSON 数组动态添加的产品计数进行求和。
<tr ng-repeat="(key,val) in form.products">
<td>{{ProductName(key)}}</td>
<td >
<input type="text" name="products" ng-model="form.products[key]" class="form-control">
</td>
</tr>
如何获得上例中的乘积之和?
最佳答案
使用lodash
假设您想要求和的值位于名为“price”的属性中:
{{_(form.products).mapValues('price').sum()}}
您可能需要首先将 lodash 纳入您的范围。在 Controller 中,类似于:
scope._ = _;
关于javascript - 如何在 AngularJS ng-repeat 中对 Json 数组值求和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35514511/