【发布时间】:2017-08-13 05:01:04
【问题描述】:
我在获取参数名称具有特定值的 JSON 对象的计数时遇到问题
在下面的 JSON 中,我想获得名称为 2 的计数:IN PROGRESS。请您帮我告诉我这里出了什么问题。
name参数出现在issues>fields>status下
JSON 数据
{
"expand": "schema,names",
"startAt": 0,
"maxResults": 50,
"total": 257,
"issues": [
{
"expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
"id": "1579217",
"fields": {
"created": "2017-08-11T13:03:52.000+0000",
"resolutiondate": null,
"status": {
"name": "IN PROGRESS",
"id": "3"
}
}
},
{
"expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
"id": "1578077",
"fields": {
"created": "2017-08-10T13:14:53.000+0000",
"resolutiondate": null,
"status": {
"name": "IN PROGRESS",
"id": "10548"
}
}
},
{
"expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
"id": "1562078",
"fields": {
"created": "2017-07-27T03:42:24.000+0000",
"resolutiondate": null,
"status": {
"name": "To Do",
"id": "10548"
}
}
}
]
}
角度 JS
var app = angular.module('myApp', ['angular-loading-bar']);
app.controller("Controller", ["$scope", "$http", "$filter", "$window",
function($scope, $http, $window, $filter) {
$scope.findTheValue = function() {
$http({
method: 'POST',
url: 'issues.json'
}).then(function(response) {
$scope.selectedCount = $filter('filter')(response.issues, {
name: 'IN PROGRESS'
}).length;
console.log($scope.selectedCount);
})
}
}
]);
【问题讨论】:
标签: angularjs json angularjs-filter