Is it possible to filter angular.js by containment in another array?

前端 未结 3 1801
孤街浪徒
孤街浪徒 2020-11-30 03:24

So if I have an array:

$scope.letters = 
[{\"id\":\"a\"},
{\"id\":\"b\"},
{\"id\":\"c\"}];

And another array

$scope.filter         


        
3条回答
  •  萌比男神i
    2020-11-30 03:44

    Quite old but I needed it and I had to change it a bit. Here's my filter "notInArray"

    app.filter('notInArray', function($filter){
    return function(list, arrayFilter, element){
        if(arrayFilter){
            return $filter("filter")(list, function(listItem){
              for (var i = 0; i < arrayFilter.length; i++) {
                  if (arrayFilter[i][element] == listItem[element])
                      return false;
              }
              return true;
            });
        }
    };
    

    });

    
          
            {{val.Name}}
          
          
            {{$chip.Name}}
          
      
    

    I supposed this can be improved but not needed in my case.

    Hope that helps someone !

提交回复
热议问题