0
如何通過getTotal()
訂購,然後按數量降序排列?如何通過示波器功能然後按字段排序
<!DOCTYPE html>
<html ng-app="shop">
<head>
<script
src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
</head>
<body>
<div ng-controller='productCtrl'>
<ul>
<li ng-repeat="x in products| orderBy:'price'">
{{x.quantity}} {{x.Name}}
<strong>{{ (x.quantity*x.price)|currency}}</strong>
</li>
</ul>
<p>Total = {{ (getTotal()) | currency }}</p>
</div>
<script>
var app=angular.module("shop",[])
.controller('productCtrl',function($scope){
$scope.products=[{quantity:4,price:42.3,Name:"HDD Sata"},
{quantity:14,price:2.83,Name:"USB Key"},
{quantity:5,price:11.03,Name:"Azerty Keyboard"},
{quantity:1,price:4.3,Name:"Mouse"}];
$scope.getTotal=function(){
var sum=0;
for(var i=0;i<$scope.products.length;i++){
sum+=($scope.products[i].price*$scope.products[i].quantity);
}
return sum;
}
});
</script>
</body>
</html>
這正是我想要的!非常感謝@ K.Toress! – Bellash 2015-04-01 12:35:55
很高興幫助你:) – 2015-04-01 12:44:50