如何使用Angular js在ng

编程入门 行业动态 更新时间:2024-10-28 09:24:57
本文介绍了如何使用Angular js在ng-repeat中使用过滤器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想用 ng-repeat 过滤一些值,我试过了,但还没有解决方案...

  • My Plunker

  • 我正在寻找三种解决方案,

(i)首先,我打算过滤 ng-module =request_role parent 在列表中。所以我曾尝试像 |过滤器:request_role。[parent'] 。

(ii)在我的第二个列表中,我正在寻找过滤 ng-module =request_role Change Agent 的值。所以我曾尝试像 |过滤器:request_role。['Change Agentent'] 。

在我的plunker第三列表中,我正在寻找过滤 ng-module =request_role 父母,更改代理的值。所以我曾尝试像 | filter:request_role。['parent,Change Agent'] 。

  • 我认为我犯了一个错误 filter ,所以请检查并更新我的plunker以及确切的解决方案,谢谢...

我的Html: -

< p style =background:black ; color:white> 1.下方列表中的父数据的过滤器request_role值< / p> < div ng-repeat =用户的问题| filter:request_role。['parent']> < small> < table border =0> < tbody> th {{question.displayName}}< / th> < th style =background:yellow;>,{{question.roles [0]}}< / th> < th style =background:light;>,{{question.request_role [0]}}< / th> < / tbody> < / table> < / small> < / div> < p style =background:black; color:white> 2。在下面的列表中过滤Change Agent数据的request_role值< / p> < div ng-repeat =用户中的问题| filter:request_role。['Change Agent']> < small> < table border =0> < tbody> th {{question.displayName}}< / th> < th style =background:yellow;>,{{question.roles [0]}}< / th> < th style =background:light;>,{{question.request_role [0]}}< / th> < / tbody> < / table> < / small> < / div> < p style =background:black; color:white> 3.Filter request_role [parent,Change Agent]数据的值在下面的列表中< / p> < div ng-repeat =用户的问题| filter:request_role。['parent,Change Agent']> < small> < table border =0> < tbody> th {{question.displayName}}< / th> < th style =background:yellow;>,{{question.roles [0]}}< / th> < th style =background:light;>,{{question.request_role [0]}}< / th> < / tbody> < / table> < / small> < / div>

我的过滤器:

1. | filter:request_role。['parent'] 2. | filter:request_role。['Change Agent'] 3. | filter:request_role。['parent,Change Agent']

  • My Plunker 。
<您可以使用自定义过滤器或直接在 ng-repeat 上应用过滤器来解决此问题,如下所示

$ b $ ol
  • < div ng-repeat =用户中的问题|过滤器:{'request_role':'parent' }>
  • < div ng-repeat =用户中的问题| filter:{'request_role':'Change Agent '}>
  • < div ng-repeat =用户的问题|过滤器:{'request_role':'Change Agent','request_role':'parent'}>
  • / strong>: plnkr.co/edit/NY3h8BCQn4gAbJsdyiJw?p=preview

    All I want to filter some values with in ng-repeat, I have tried but haven't got a solution...

    • My Plunker.

    • I am looking for three kinds of solution,

    (i) In my plunker first, i am looking to filter ng-module="request_role" value of parent in the list. so I had tried like | filter: request_role.[parent'].

    (ii) In my plunker second list, i am looking to filter ng-module="request_role" value of Change Agent. so I had tried like | filter: request_role.['Change Agentent'].

    (i) In my plunker third list, i am looking to filter ng-module="request_role" value of parent,Change Agent. so I had tried like | filter: request_role.['parent,Change Agent'].

    • I think I have done a mistake in filter, so please check and update my plunker as well to know exact solution, thanks...

    My Html:-

    <p style="background: black;color:white">1.Filter request_role value of `parent` data's in below list</p> <div ng-repeat="question in users | filter: request_role.['parent']"> <small> <table border="0"> <tbody> <th>{{question.displayName}}</th> <th style="background: yellow;">,{{question.roles[0]}}</th> <th style="background: light;">,{{question.request_role[0]}}</th> </tbody> </table> </small> </div> <p style="background: black;color:white">2. Filter request_role value of `Change Agent ` data's in below list</p> <div ng-repeat="question in users | filter: request_role.['Change Agent']"> <small> <table border="0"> <tbody> <th>{{question.displayName}}</th> <th style="background: yellow;">,{{question.roles[0]}}</th> <th style="background: light;">,{{question.request_role[0]}}</th> </tbody> </table> </small> </div> <p style="background: black;color:white">3.Filter request_role Both value of ["parent","Change Agent"] data's in below list</p> <div ng-repeat="question in users | filter: request_role.['parent,Change Agent']"> <small> <table border="0"> <tbody> <th>{{question.displayName}}</th> <th style="background: yellow;">,{{question.roles[0]}}</th> <th style="background: light;">,{{question.request_role[0]}}</th> </tbody> </table> </small> </div>

    My filter:-

    1. | filter: request_role.['parent'] 2. | filter: request_role.['Change Agent'] 3. | filter: request_role.['parent,Change Agent']

    • My Plunker.

    解决方案

    You can solve this using a custom filter or directly by applying a filter on ng-repeat as shown below

  • <div ng-repeat="question in users | filter: {'request_role':'parent'}">
  • <div ng-repeat="question in users | filter: {'request_role':'Change Agent'}">
  • <div ng-repeat="question in users | filter: {'request_role':'Change Agent','request_role':'parent'}">
  • Working Plunker: plnkr.co/edit/NY3h8BCQn4gAbJsdyiJw?p=preview

    更多推荐

    如何使用Angular js在ng

    本文发布于:2023-07-07 13:33:52,感谢您对本站的认可!
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:如何使用   Angular   ng   js

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!