你可能會想使用你的成功部分內angulars的foreach。在這裏的foreach文件 - link我創建這個小提琴,顯示我的意思 - link
代碼從下面的jsfiddle:
HTML:
<div ng-app="test" ng-controller="customersController">
<h1> Test </h1>
<h4> Tens = {{tens}}</h4>
<h4> Twenties = {{twenties}}</h4>
<h4> Thirties = {{thirties}}</h4>
<table>
<tr ng-repeat="x in Number">
<td>{{ x.number }}</td>
<td>{{ x.resource }}</td>
<td>{{ x.status }}</td>
</tr>
</table>
JS:
angular.module('test', [])
.controller('customersController', function ($scope) {
$scope.Number = [
{number: 1, resource: 1, status: 10},
{number: 1, resource: 1, status: 10},
{number: 2, resource: 2, status: 20},
{number: 3, resource: 3, status: 30}
];
// Set your variables to 0 at first
$scope.tens = 0;
$scope.twenties = 0;
$scope.thirties = 0;
// Use angulars for each to loop over your numbers
angular.forEach($scope.Number, function(value, key) {
// Increment each number by one when you hit it
if (value.status == 10){
$scope.tens++
}else if (value.status == 20){
$scope.twenties++
}else if (value.status == 30){
$scope.thirties++
}
});
});
那麼問題是什麼? – tymeJV 2014-09-30 15:42:44
Sry我制定了這個問題很糟糕。我有3個不同的地位,有10-20和30個。我想在10,20和30上有多少個計數器,所以它會像狀態:30 = 100次,狀態:20 = 50次狀態:10 = 33次 – adam 2014-09-30 16:21:55