如何根据超过 1 属性 筛选记录并获取计数

How to filter records based on more than 1 property and get count

我的控制器中有这样的数据:

$scope.items = [
{
  id: "0",
  name: "Nurse1",
  icon: "rooms_nurse.svg",
  type: "nurse",
  location: build-A
},
{
  id: "1",
  name: "Nurse2",
  icon: "rooms_nurse.svg",
  type: "nurse",
  location: build-A
},
{
  id: "1",
  name: "Dr",
  icon: "rooms_dr.svg",
  type: "Dr",
  location: build-B
},
{
  id: "2",
  name: "Dr",
  icon: "rooms_dr.svg",
  type: "Dr",
  location: build-B
}]

我想要的是根据位置和类型过滤此数据,并查找结果计数,例如每个位置有多少 nurses/Dr:

$scope.items = [
{
count:2
  icon: "rooms_nurse.svg",
  type: "nurse",
  location: build-A
},
{

  count:2
  icon: "rooms_dr.svg",
  type: "Dr",
  location: build-B
},
 ......    
]

我知道有过滤服务,但它只适用于一个 属性

   $scope.content = $filter('countBy')($scope.items,'type');

有人可以帮我解决这个问题吗?

您可以简单地创建一个自定义过滤器:

angular.module('filterMore', []).
  filter('countBy', function() {
    return function(type,location) {
      var out = [];
      // Filter logic here, adding matches to the out var.
      return out;
    }
  });