角。js:过滤ng-repeat,不存在于数组中

时间:2022-08-23 23:36:43

I need to filter items in ng-repeat so that only the items which not appear in alreadyAddedValues() array will be shown:

我需要过滤ng-repeat中的条目,只显示alreadyAddedValues()数组中没有的条目:

<ul class="dropdown-menu">
    <li ng-repeat="v in values() | filter: { ????? } ">{{value.name}}</li>
</ul>

$scope.values() = function(){
    ................
}

$scope.alreadyAddedValues() = function()
{
    //returns an array
}

The search of an already added value should perform by value.shortName

对已经添加的值的搜索应该以value. shortname来执行。

1 个解决方案

#1


30  

You can, for example, use a custom function to do the filtering:

例如,您可以使用自定义函数进行过滤:

<li ng-repeat="v in values() | filter:filterAlreadyAdded ">{{value.name}}</li>

On the controller:

控制器:

$scope.filterAlreadyAdded = function(item) {
    // filter logic here...
    // return false if item already added, true otherwise
};

jsfiddle: http://jsfiddle.net/bmleite/5VbCJ/

jsfiddle:http://jsfiddle.net/bmleite/5VbCJ/

#1


30  

You can, for example, use a custom function to do the filtering:

例如,您可以使用自定义函数进行过滤:

<li ng-repeat="v in values() | filter:filterAlreadyAdded ">{{value.name}}</li>

On the controller:

控制器:

$scope.filterAlreadyAdded = function(item) {
    // filter logic here...
    // return false if item already added, true otherwise
};

jsfiddle: http://jsfiddle.net/bmleite/5VbCJ/

jsfiddle:http://jsfiddle.net/bmleite/5VbCJ/