【问题标题】:How to apply filter in ng-repeat for object's fields?如何在 ng-repeat 中为对象的字段应用过滤器?
【发布时间】:2016-05-31 04:35:34
【问题描述】:

我想为选定的对象字段应用角度过滤器。我有状态列表 ["waiting"、"conform"、"rac"],当我选择一个状态时,它应该提供表中具有该状态的人员的信息。

例如,如果某人的票符合,那么当我们选择status = conform 时,只有显示的人应该有符合票。等待和 rac 也是如此

请查看演示和代码。它不工作。请帮忙.. Please see the demo

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>

控制器:

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

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

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

【问题讨论】:

  • 也发布您的过滤器代码以及为什么您不在表达式中使用过滤器{{ person.name | status}}
  • 您希望对状态字段做什么?在该字段上按字母顺序排序?
  • 命令是ng-repeat 而不是ng-repead
  • @PankajParkar,如果您正在班加罗尔寻找机会,您好 Pankaj。我可以在我公司推荐你。我的公司名称是 Black-Buck Logistic。您可以从 1.timesofindia.indiatimes.com/tech/tech-news/… 获取有关该公司的更多信息

标签: javascript angularjs angularjs-ng-repeat angularjs-filter


【解决方案1】:

具体应用filter 超过status 属性,而不是直接使用过滤器,它将用作包含过滤器(使用压缩器设置为true 以获得精确匹配)。通过包含过滤器,您将在列表中获得人员,该列表将命名您正在搜索的字符串中的任何一个status

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

ng-repead 的错字更正为ng-repeat

Demo here

【讨论】:

【解决方案2】:
<tr ng-repeat="person in list| filter: status">

你拼错了重复

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-12
    • 1970-01-01
    • 2016-01-08
    • 1970-01-01
    • 2015-01-16
    相关资源
    最近更新 更多