角度过滤器自定义搜索对象

时间:2016-12-21 12:32:42

标签: javascript jquery angularjs

我有一个搜索框,我希望过滤器同时检查skuname和osname,但在搜索单个文件时工作正常我想用这两个组合进行搜索

<input type="text" class=" search-query form-control" ng-model="lansearch" placeholder="Search" />

<tr ng-repeat-start="detail in details | filter:  lansearch ">
<td  >
<div style="margin-top:5px">
<a class="ng-binding" ng-bind="(detail.skuname)+'' +'&nbsp;&nbsp;&nbsp;'+'' +(detail.osname)"> </a>
</div>
</td>

1 个答案:

答案 0 :(得分:0)

您只需要指定要查找的对象,如下所示:这将与AND运算符一样工作。

<tr ng-repeat="detail in details | filter:  {skuname: lansearch, osname: lansearch} ">

另一个选项可能是一个函数:

  • 在您的控制器内:

    $scope.filterFunction= function(user){
        return user.skuname=== $scope.lansearch|| 
            user.osname=== $scope.lansearch;
    };
    

然后在你的html中添加过滤功能:

 ng-repeat="detail in details | filter:  filterFunction