通过使用AngularJS

时间:2016-02-25 14:29:44

标签: javascript html angularjs json filtering

我有一个项目列表。一个项目的示例:

{"id":7,"name":"ItemName","status":"Active","statusFrom":"2016-01-04T00:00:00","development":"Started","devStartedFrom":"2016-01-04T00:00:00","owner":"Owner"}

我希望过滤器只查看名称状态所有者并返回(OR运算符)对象。过滤器的定义如下:

<tr ng-repeat="item in items | filter: {name:myFilterquery, status:myFilterquery, owner:myFilterquery}">

过滤器通过跟随AND运算符返回对象。

如何定义过滤器以仅按对象的特定字段进行查询,但是遵循OR运算符?

2 个答案:

答案 0 :(得分:0)

您可以自己进行过滤,然后在AND上选择OR:

[
    {id: 123, name: 'abc'},
    {id: 456, name: 'xyz'},
    {id: 999, name: 'qwe'},
].filter(item => item.id === 123 || item.name === 'xyz') // [{id: 123, name: 'abc'}, {id: 456, name: 'xyz'}]

更新:啊,你的意思是加价!

在这里回答?:How to filter multiple values (OR operation) in angularJS

答案 1 :(得分:0)

选择angular-filter库并以这种方式定义解决方案:

<tr ng-repeat="item in items | filterBy : ['name', 'status', 'owner'] : filterQuery">