简体   繁体   English

如何在对象字段的ng-repeat中应用过滤器?

[英]How to apply filter in ng-repeat for object's fields?

I want to apply angular filter for selected object field. 我想为选定的对象字段应用角度过滤器。 I have list of statuses ["waiting", "conform", "rac"], when I select a status it should give information of persons in the table which have that status. 我有状态列表[“等待”,“符合”,“rac”],当我选择状态时,它应该给出表中具有该状态的人的信息。

For example if some person ticket conform, then when we select status = conform then only person shown should have conform ticket. 例如,如果某个人票符合,那么当我们选择status = conform只有所显示的人才应该有符合票证。 Similarly for waiting and rac 同样的等待和rac

Please see the demo and code. 请参阅演示和代码。 It is not working. 它不起作用。 Please help.. Please see the demo 请帮助.. 请参阅演示

HTML HTML

<div class="col-md-12">
   <table>
      <thead>
        <tr>Name</tr>
        <tr>Status</tr>
      </thead>
      <tbody >
        <tr ng-repeat="person in list| filter: status">
          <td>{{person.name}}</td>
          <td>{{person.status}}</td>
        </tr>
      </tbody>
   </table>
</div>

Controller: 控制器:

$scope.status_list=["waiting", "conform", "rac"];
  $scope.list = [
  { 'name': 'A',

    'status':'waiting'
  },
  { 'name': 'B',

     'status':'conform'
  },
  { 'name': 'C',
     'status':'rac'
  }
]

Be specific to apply filter over status property rather than directly using filter which will work as contains filter (use compactor set to true for getting exact match). 特定于将filter应用于status属性而不是直接使用过滤器,该过滤器将用作包含过滤器(使用compactor设置为true以获得完全匹配)。 By having contains filter you will get person in list which will have name any one of string which you are searching for status 通过包含过滤器,您将获得列表中的人员,该列表中将包含您要搜索status的字符串中的任何一个

<tr ng-repeat="person in list| filter: { status: status}: true">
   <td>{{person.name}}</td>
   <td>{{person.status}}</td>
</tr>

Correct typo of ng-repead to ng-repeat 纠正ng-repeadng-repeat

Demo here 在这里演示

<tr ng-repeat="person in list| filter: status">

你拼写重复错了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM