【问题标题】:AngularJS filter on deep propertiesAngularJS 过滤深层属性
【发布时间】:2016-04-16 20:48:00
【问题描述】:

我正在尝试过滤字符串值上的一些数据,但我无法获得正确的语法。这是我的代码:

<tbody ng-repeat="qbRating in vm.scope.qbRatings | filter:'tournament.season.seasonName':'2022'  | ratingFilter | orderBy:'-rating'">
    <tr class="qbrating2022">
        <td>{{ qbRating.tournament.season.seasonName }}</td>
        <td>{{ qbRating.team.teamName }}</td>
        <td>{{ qbRating.completion }}</td>
        <td>{{ qbRating.gain }}</td>
        <td>{{ qbRating.touchdown }}</td>
        <td>{{ qbRating.interception }}</td>
        <td>{{ qbRating.rating }}</td>
    </tr>
</tbody>

过滤器没有返回任何数据,即使它应该返回,但在控制台中没有返回错误。

谁能帮我把语法弄对吗?

【问题讨论】:

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


    【解决方案1】:

    您应该通过指定要匹配的对象来对特定属性进行过滤,例如filter: {'tournament': {season : {seasonName:'2022'}}}

    ng-repeat="qbRating in vm.scope.qbRatings | filter: {'tournament': {season : {seasonName:'2022'}}} | ratingFilter | orderBy:'-rating'"
    

    【讨论】:

    • 太好了,正是我正在寻找的答案!
    • @user517406 很高兴知道这一点。谢谢:-)
    【解决方案2】:

    filter 接受字符串、对象或函数,而不是数组filter api

    【讨论】:

    • 我的错误,过滤器应该是 filter:'tournament.season.seasonName':'2022',但它没有返回任何内容。见编辑
    • @user517406 ok) 第二个参数是一个比较器,应该是一个函数,true 或 undefined
    猜你喜欢
    • 2015-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-11
    • 2013-12-17
    • 2015-02-20
    • 2017-02-21
    相关资源
    最近更新 更多