在 AngularJS 中过滤不等于 [英] Filter NOT equals in AngularJS

查看:36
本文介绍了在 AngularJS 中过滤不等于的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在客户端有一组对象.数组中的对象如下所示:

I have a array of objects, in client side. The object in array look like this:

{
    code: 0,
    short_name: 'a',
    type: 1
}

我尝试将此数组过滤为 2 个数组:

I try to filter this array to 2 arrays:

  1. 类型 === 1
  2. 类型为 !== 1

我是这样做的:

$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?

谢谢!

推荐答案

同样,如果您只是要filter,请使用 本机方法:

Again, if you are just going to filter, use the native method instead:

$scope.array1 = data.filter(x => x.type === 1);
$scope.array2 = data.filter(x => x.type !== 1);

这篇关于在 AngularJS 中过滤不等于的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆