对象中的角度过滤器空数组
angular filter empty array in an object
我有这个对象数组
var list = [{
"questionId": 1,
"correctChoiceIds": [],
"choiceId": 0,
"number": 1
}, {
"questionId": 1,
"correctChoiceIds": [1234, 4567],
"choiceId": 0,
"number": 2,
}, {
"questionId": 2,
"correctChoiceIds": [],
"choiceId": 0,
"number": 3
}];
//This filter gives me an array with list[0] and list[1]
var filterQuestion = $filter('filter')(list, { questionId: 1 }, true);
我想为它们的correctChoiceIds
筛选所有具有空数组的对象。
var filterNoCorrectChoice= $filter('filter')(list, { correctChoiceIds: [] }, true);
这就是我想到的,但它根本没有给我任何东西。我不确定这是否是正确的方式,也不确定为什么会一无所获。
请参阅演示
使用这样的过滤器,
var filterNoCorrectChoice= $filter('filter')(list,function(item) {
// must have array, and array must be empty
return item.correctChoiceIds && item.correctChoiceIds.length === 0;
});
方法过滤本机
var filterQuestion = list.filter(function(el){ return el.correctChoiceIds.length<1; });
// result
console.log(filterQuestion);
我想为他们的
correctChoiceIds
筛选所有具有空数组的
你不需要一个角度过滤器,使用一个标准的本地javascript过滤器。。。
list.filter(x => !x.correctChoiceIds.length);
相关文章:
- angularjs ng基于点击时的数组值重复过滤器
- javascript和具有唯一密钥的es6过滤器数组
- 数组过滤器导致无限$digest循环
- (角度.js)如何通过过滤器计算数组中有多少项目
- AngularJS过滤器不适用于我的数据:关联数组
- 键上的javascript数组对象过滤器
- 如何遍历对象数组并将值放入过滤器中
- 如何使用angular js过滤器格式化数组中的值
- Javascript数组过滤器:获取正确的上下文
- 如何在angularjs中对指令内部的JSON数组使用过滤器
- 对象中的角度过滤器空数组
- 数组中的Angular js过滤器数组
- 数组中的javascript过滤器数组
- 通过过滤器数组设置对象数组的属性
- 使用类似查询的对象过滤器数组下划线
- 在 JavaScript 中使用第二个数组的过滤器数组
- rxjs的filter方法没有返回过滤器数组
- 过滤器数组递归查找父级
- 基于this.props.params.id的React过滤器数组
- JavaScript 过滤器数组多个条件