如何从AngularJS过滤器中的数组中排除对象? [英] How to exclude an object from an array in AngularJS filter?

查看:185
本文介绍了如何从AngularJS过滤器中的数组中排除对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在无序列表中显示商店列表。我想从所有商店中排除currentShop。我写了这样的内容:

 < ul class =dropdown-menu dropdown-menu-default> 
< li ng-repeat =shop.account.shops | shop:!currentShop}>
< a href =#/ profile>
< i class =icon-user>< / i> {{shop.name}}< / a>
< / li>
< / ul>

我错了?

解决方案

这里你有一个工作的例子。你可以通过范围过滤表达式

  ng-repeat =item在过滤器中:myExpression

定义您的过滤器函数;

  $ scope.myExpression = function(shop){
return shop.id!== $ scope.current.id;
};


I want to display a list of shops in an unordered list. I want to exclude "currentShop" from all shops. I wrote something like:

<ul class="dropdown-menu dropdown-menu-default">
                <li ng-repeat="shop in user.account.shops | filter:!currentShop}">
                    <a href="#/profile">
                        <i class="icon-user"></i> {{shop.name}} </a>
                </li>
            </ul>

Where am I wrong?

解决方案

Here you have a working example. You can filter by a scope expression

ng-repeat="item in list | filter: myExpression"

Define your filter function;

$scope.myExpression= function(shop) {
  return shop.id !== $scope.current.id;
};

这篇关于如何从AngularJS过滤器中的数组中排除对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆