AngularJS 过滤器已选择的选项 [英] AngularJS filter already selected options

查看:26
本文介绍了AngularJS 过滤器已选择的选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 3 个选择,它们都共享相同的选项.由于在其中一个选项中选择了一个选项,我想将其从其他选择中过滤掉.

I have 3 selects that all share the same options. As an option is selected in one of them, I want to filter it out of the other selects.

我在这里刺了一下,但没有任何运气.http://plnkr.co/edit/ERGTbQSjoX3IpGAomcUn?p=preview

I took a stab at it here and did not have any luck. http://plnkr.co/edit/ERGTbQSjoX3IpGAomcUn?p=preview

<select name="ques1" ng-model="q1" required>
    <option value="">question</option>
    <option ng-repeat="question in questions | filter: { Id : '!' + q2 } | filter: { Id : '!' + q3 }" value="{{ question.Id }}">{{ question.Question }}</option>
</select>

有什么建议吗?并提前致谢.

Any advice? And thanks in advance.

推荐答案

我终于让它工作了.根据文档.您可以将函数作为参数传递给过滤器.所以我创建了一个函数,它返回一个将传递给过滤器的函数:

I finally make it work. According to the document. You can pass a function as argument to the filter. So I created a function that returns a function which will be passed to filter:

  $scope.negative = function(){
    var arr = Array.prototype.slice.call(arguments) 

     return function(value ,index, array){
       var scope = $scope;

       for(var i = 0 ; i<arr.length ;i++) {
          if(value.Id == scope[arr[i]]) return false;
       }

       return true;

     }
  }

这是一个示例

这篇关于AngularJS 过滤器已选择的选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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