第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

計算AngularJS ng-repeat中重復元素的總和

計算AngularJS ng-repeat中重復元素的總和

蝴蝶不菲 2019-07-30 11:25:39
計算AngularJS ng-repeat中重復元素的總和下面的腳本顯示了使用的購物車ng-repeat。對于數(shù)組中的每個元素,它顯示項目名稱,其數(shù)量和小計(product.price * product.quantity)。計算重復元素總價的最簡單方法是什么?<table>     <tr>         <th>Product</th>         <th>Quantity</th>         <th>Price</th>     </tr>     <tr ng-repeat="product in cart.products">         <td>{{product.name}}</td>         <td>{{product.quantity}}</td>         <td>{{product.price * product.quantity}} €</td>     </tr>     <tr>         <td></td>         <td>Total :</td>         <td></td> <!-- Here is the total value of my cart -->     </tr></table>
查看完整描述

3 回答

?
神不在的星期二

TA貢獻1963條經(jīng)驗 獲得超6個贊

在模板中

<td>Total: {{ getTotal() }}</td>

在控制器中

$scope.getTotal = function(){
    var total = 0;
    for(var i = 0; i < $scope.cart.products.length; i++){
        var product = $scope.cart.products[i];
        total += (product.price * product.quantity);
    }
    return total;}


查看完整回答
反對 回復 2019-07-30
  • 3 回答
  • 0 關注
  • 884 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號