【发布时间】:2017-02-14 15:40:45
【问题描述】:
我试图让这段代码得到所有detalle.price 元素总和的最终数字。它们都是数字,所以我需要将它们相加并将最终数字发布到sum()。
<div id="pedidos_table">
<div id="pedidos_table_item" ng-repeat="detalle in detalles">
<p id="pedidos_table_item_name">{{detalle.name}}</p>
<p id="pedidos_table_item_price">{{detalle.price}}$</p>
</div>
</div>
<div id="pedidos_table_total">
<p id="pedidos_table_item_name">TOTAL</p>
<p id="pedidos_table_item_price">{{sum()}}$</p>
</div>
我试过这样做:
$scope.sum = function(){
var total = 0;
total += detalle.price;
return total
}
我知道缺少什么,但我不知道是什么。
【问题讨论】:
-
发布您的 json 文件。
标签: html angularjs angularjs-scope ng-repeat