Filter在AngularJS中不等于 [英] Filter NOT equals in AngularJS
本文介绍了Filter在AngularJS中不等于的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
数组中的对象如下所示:
{
code:0,
short_name :'a',
type:1
}
我尝试过滤此数组为2个数组:
- 使用类型=== 1
- 1
我做了这个:
$ scope.array1 = $ filter('filter')(data,{type:1},true);
$ scope.array1 = $ filter('filter')(data,{type:!1});
但是不等于没有工作...我能做什么?
谢谢!
解决方案
同样,如果您只是要 filter
,使用
$ $ p $ $ scope.array1 = data.filter(function(x){return(nofollow)> native method ) x.type === 1;});
$ scope.array2 = data.filter(function(x){return x.type!== 1;});
在ES2015中
$ scope.array1 = data.filter(x => x.type === 1);
$ scope.array2 = data.filter(x => x.type!== 1);
I have a array of objects, in client side. The object in array look like this:
{
code: 0,
short_name: 'a',
type: 1
}
I try to filter this array to 2 arrays:
- With type === 1
- With type !== 1
I did this:
$scope.array1 = $filter('filter')(data, {type: 1}, true);
$scope.array1 = $filter('filter')(data, {type: !1});
But the not-equal didn't work... what can I do?
Thank you!
解决方案
Again, if you are just going to filter
, use the native method instead:
$scope.array1 = data.filter(function(x) { return x.type === 1; });
$scope.array2 = data.filter(function(x) { return x.type !== 1; });
In ES2015
$scope.array1 = data.filter(x => x.type === 1);
$scope.array2 = data.filter(x => x.type !== 1);
这篇关于Filter在AngularJS中不等于的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文