如何在html中为多个条件编写过滤器?

时间:2016-09-07 07:55:27

标签: html angularjs html5

enter image description here我有下面给出的代码。 我正在使用故事所有者和故事状态。

ng-repeat="item in IterationStories | 
filter: {Story: {storyOwner: filterRequestor}} | 
filter: {Story: {state: filterKey}} " //when I select state it is working

2 个答案:

答案 0 :(得分:1)

您可以在官方Angular过滤器文档here上找到一个很好的示例。

所以,如果你的"项目"对象看起来像这样:

{
   storyOwner: 'something',
   state: 'deleted',
}

您可以像这样实现过滤器:

<label>Story owner <input ng-model="search.storyOwner"></label>
<label>State <input ng-model="search.state"></label>
<table>

  <tr ng-repeat="item in IterationStories | filter:search">

  </tr>
</table>

答案 1 :(得分:0)

    //for third solution 
    $scope.myFilter = function (item) {
        return (item.storyOwner == $scope.Story.storyOwner || item.state:$scope.Story.filterKey );
    }
<!--first solution-->
    ng-repeat="item in IterationStories | filter:{storyOwner: filterRequestor, state: filterKey} "

<!--second solution-->
    ng-repeat="item in IterationStories | filter: {Story: {storyOwner: filterRequestor, state: filterKey}}"

<!--third solution-->
    ng-repeat="item in IterationStories | filter:myFilter"