I have the following JSON data and I'm trying to determine the number of objects with Status: 1
in the JSON. The approach I've taken so far is not working.
I understand that ng-filter should only be applied to Arrays, but I'm struggling to implement it in this JSON structure. Can anyone provide assistance?
I'm receiving an error as expected, but I'm unsure how to resolve this issue in my scenario.
[filter:notarray] Expected array but received:
In the JSON data below, you'll see that I have Arrays nested within Arrays, and I need to count the instances where Status has a value of 1.
Expected Output
Count Of 1st Array : 1 Count of 2nd Array : 3 Count of 3rd Array : 1
JSON Data
[
[{
"id": 252323,
"orderId": 223505,
"status": 1,
"executedOn": "13/Sep/17",
"executedBy": "Person A",
"executedByDisplay": "Person A",
"cycleId": 3994,
"cycleName": "Cycle A",
"versionId": 21291,
"versionName": "Version A",
"issueKey": "Key-12561"
}],
[{
"id": 253077,
"orderId": 224047,
"status": 1,
"executedOn": "26/Sep/17",
"executedBy": "Person B",
"executedByDisplay": "Person B",
"cycleId": 4012,
"cycleName": "Cycle B",
"versionId": 22912,
"versionName": "Version B",
"issueKey": "Key-12580"
}, {
"id": 253076,
"orderId": 224046,
"status": 2,
"executedOn": "20/Sep/17",
"executedBy": "Person B",
"executedByDisplay": "Person B",
"cycleId": 4012,
"cycleName": "Cycle B",
"versionId": 22912,
"versionName": "Version B",
"issueKey": "Key-12578"
}, {
"id": 253075,
"orderId": 224045,
"status": 1,
"executedOn": "20/Sep/17",
"executedBy": "Person B",
"executedByDisplay": "Person B",
"cycleId": 4012,
"cycleName": "Cycle B",
"versionId": 22912,
"versionName": "Version B",
"issueKey": "Key-12582"
}, {
"id": 253074,
"orderId": 224044,
"status": 1,
"executedOn": "20/Sep/17",
"executedBy": "Person B",
"executedByDisplay": "Person B",
"cycleId": 4012,
"cycleName": "Cycle B",
"versionId": 22912,
"versionName": "Version B",
"issueKey": "Key-12584"
}],
[{
"id": 255168,
"orderId": 226138,
"status": 1,
"executedOn": "26/Sep/17",
"executedBy": "Person A",
"executedByDisplay": "Person A",
"cycleId": 4022,
"cycleName": "Cycle C",
"versionId": 21291,
"versionName": "Version A",
"issueKey": "Key-12617"
}]
]
Angular JS Code
var app = angular.module('studentApp', []);
app.controller('StudentCntrl', function($scope, $http, $filter) {
$http.get('data.json').then(function(response) {
$scope.value = response.data;
$scope.value.forEach(function(items) {
$scope.eachValue = items;
items.forEach(function(insideItems) {
passvalue = $filter('filter')(insideItems, function(inputs) {
if (inputs.status == '1')
console.log(inputs.length);
return inputs;
});
});
});
});
});