如何基于多个属性筛选记录并获取计数
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
}]
我想要的是根据位置和类型过滤这些数据,并找到结果计数,比如每个位置有多少护士/医生:
$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;
}
});
相关文章:
- 将一个表的id与另一个表中的user_id进行匹配,以获取mysql中的记录
- 正在获取错误:'没有找到monkeyID为“”的按钮;LOGIN”;记录
- 如何加速ajax调用以从php文件中获取记录
- 从开始到结束的数字记录json中获取记录
- 如何使用nlapiLoadRecord获取记录类型
- 根据用户在边栏中的选择获取记录
- 谷歌电子表格 - 从Zoho获取记录
- 使用1个HTML表单:要求用户提供唯一标识符,从数据库中获取记录,解析为JSON,使用jquery填充插件填充HTML页
- 如何在ExtJS存储中获取记录的预排序索引
- 我需要从一个表中获取记录,其中列值将以“某个值”开头并以“另一个某个值”结尾
- EXTJS 3.4如何在选择更改时获取记录数据视图
- 使用相对时间间隔条件获取记录
- 从表中获取记录
- 使用javascript函数在json对象中获取记录需要更多时间
- 如果使用laravel框架,如何在javascript或ajax中传递用户id以从数据库中获取记录
- 多维数组-用于获取记录信息的javascript while循环
- Ember数据首先从存储获取记录,而不是使用param从API获取记录
- 合金用户界面 - 更新后获取记录
- 在保存操作之前获取记录's指南
- 如何在不知道键名的情况下从对象获取记录