任何人都可以帮助我获取状态字段
的计数从JSON下面我想知道有多少归档了Status = Open and Closed和Assigned
如何在Anular JS中获取值
Angular JS(这里我从URL获取JSON值,它包含在JSON数据下面
var app = angular.module('defectApp', ["ngTable"]);
app.controller('defectController', [
'$scope',
'$http',
function($scope, $http) {
$http({method: 'POST', url: '/angular/defect/defect.json'}).success(function(response) {
$scope.post = response;
})
},
]);
JSON数据
{
"data": [
{
"type": "defect",
"id": 1,
"user-01": "John",
"status": "Open",
"severity": "1 - Urgent"
},
{
"type": "defect",
"id": 2,
"user-01": "John",
"status": "Open",
"severity": "3 - High"
},
{
"type": "defect",
"id": 3,
"user-01": "John",
"status": "Assigned",
"severity": "3 - High"
},
{
"type": "defect",
"id": 4,
"user-01": "John",
"status": "Closed",
"severity": "4 - Medium"
},
{
"type": "defect",
"id": 5,
"user-01": "John",
"status": "Closed",
"severity": "4 - Medium"
}
]
}
答案 0 :(得分:3)
您可以使用Angular的$filter
服务。
var openCount = $filter('filter')(response.data, {status: 'Open'}).length,
closedCount = $filter('filter')(response.data, {status: 'Closed'}).length,
assignedCount = $filter('filter')(response.data, {status: 'Assigned'}).length;
过滤器会将数组简化为具有特定状态的对象,然后您只需计算数组中的数字。