Angular 带有 JSON 对象数组过滤器的 JS 控制器

Angular JS Controller with Filter For JSON Array Of Objects

我有以下类型的 JSON,我想在 JSON 中找到带有 Status : 1 的对象的数量,我尝试了以下方法但它不起作用。

而且我知道 ng-filter 只需要应用于数组,但我在下面的 JSON 数据中找不到这样做的方法,有人可以帮助我吗

我收到了预期的错误,但在我的案例中如何解决这个问题

[filter:notarray] Expected array but received:

Plunker Demo

在下方 JSON 数据 如您所见,我有 Array with Arrays,我应该得到 值为 1状态的计数

预期输出

第一个数组的计数:1 第二个阵列的数量:3 第三个数组的计数:1

JSON数据

    [
  [{
    "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"
  }]
]

AngularJS代码

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;
        });
      });

    });
  });
});

你可以简单地使用java script array filter类似

的东西
 arr.filter( function(a){return a.status==1}).length

或使用angular

 $filter('filter')(v, function(vc) {return vc.status ==1}).length

Here is working demo