angularjs 在使用Angular过滤器时使用OR条件

qybjjes1  于 7个月前  发布在  Angular
关注(0)|答案(1)|浏览(89)

我刚开始使用AngularJS,遇到了以下问题:
我从一个API请求中获得了这样的对象:

{
  "recid": "1576",
  "title": "19th Century UK Periodicals",
  "description": "Bevat ruim 180 gescande tijdschriften die full text doorzoekbaar zijn",
  "type": "tek",
  "tags": "Engeland",
  "primair": "b:bio",
  "secundair": "h:eng,h:ges",
},

字符串
我需要通过选择属于'primair'或'secundair'字段的数据进行过滤,我怎么能这样做,因为链接使用一种AND而不是OR。

5sxhfpxr

5sxhfpxr1#

最简单的方法是使用自定义过滤器函数。在您的控制器中,您可以像这样定义它:

function YourController ($scope) {
   $scope.filterFn = function (v) {
     return (v.primair === 'somevalue') || (s.secundair === 'someothervalue');
   };
 }

字符串
在你的模板中,你可以这样使用它:

<li ng-repeat="item in yourlist | filter:filterFn">{{item.title}}</li>

相关问题