从列分类的部分总金额

时间:2013-07-02 19:11:52

标签: angularjs

尝试使用AngularJS做一个例子 - 这是我从JSON数据获得的ngRepeat输出:

Gadgets - $45
Power Bill - $50
Gadgets - 45
Power Bill - 50

所以我想获得Power Bill支付的总金额和100和90等小工具的总支出 - 如何使用AngularJS从ngRepeat动态获取?

感谢您的提示和帮助!提前谢谢!

1 个答案:

答案 0 :(得分:0)

你可以编写一个控制器函数来获取总数,然后点击一个按钮就可以调用它。
// Item List Arrays
$scope.items = [2, 3, 4]; // this can be replace by ur json data u get

$scope.total = 0;
$scope.getTotal = function() { <br>

    for(var i=0; i< $scope.items.length; i++) { 

        $scope.total+= $scope.items[i];

        console.log($scope.total);
    }

}

// DOM

$scope.total = 0;
$scope.getTotal = function() { <br>

    for(var i=0; i< $scope.items.length; i++) { 

        $scope.total+= $scope.items[i];

        console.log($scope.total);
    }

}
相关问题