需要在角度ui选择中添加多个滤镜

时间:2017-02-02 09:03:45

标签: angularjs angularjs-filter angular-filters angular-ui-select

需要在angular uiselect2。

中添加多个过滤器
<div class="form-group ">
    <ui-select id="abc" ng-model="abc" multiple theme="bootstrap"  >
       <ui-select-match placeholder="Select abc..." class="ui-select-match">{{$item.name | capitalize}}</ui-select-match>
        <ui-select-choices id= "abchoice" class="ui-select-choices" repeat="item in itemDetails| filter: $select.search ">
               <div id="selected_{{item}}" ng-bind-html="item .name | capitalize | highlight: $select.search" style="padding: 0px; "></div>
         </ui-select-choices>
     </ui-select>

</div>

我有

itemDetails=["a","b","c"]
orderItem=["c"] 

我需要通过orderItem按filter: $select.search过滤它。如何在ui-select中添加此自定义过滤器?

在下拉列表中我只得到a,b,我应该过滤c

2 个答案:

答案 0 :(得分:1)

尝试类似的内容

<ui-select multiple ng-model="orderItem.items" theme="select2" ng-disabled="disabled" style="width: 300px;">
   <ui-select-match placeholder="Select order item...">{{$item}}</ui-select-match>
    <ui-select-choices repeat="item in itemDetails | filter:$select.search">
      {{item}}
    </ui-select-choices>
 </ui-select>
  <p>Selected: {{orderItem.items}}</p>

在您的视图中

 'use strict';
    var app = angular.module('demo', ['ui.select']);
    app.controller('DemoCtrl', function($scope) {
      $scope.itemDetails = ['a','b','c'];
      $scope.orderItem = {};
      $scope.orderItem.items = null;
    });
  // filter to exclude a value/item
  app.filter('Exclude', function() {
      return function( items) {
        var filtered = [];
        angular.forEach(items, function(item) {
          if(item!='c'){
            filtered.push(item);
          }
        });
        return filtered;
      };          
 });

Plunker 1

使用过滤器排除项目

<强>控制器:

<p>Selected: {{orderItem.items}}</p>
  <ui-select ng-model="orderItem.items" theme="select2" ng-disabled="disabled" style="width: 300px;">
    <ui-select-match placeholder="Select order item...">{{$select.selected}}</ui-select-match>
    <ui-select-choices repeat="item in itemDetails | Exclude |  filter:$select.search">
      {{item}}
    </ui-select-choices>
  </ui-select>

查看:

httpd-ssl.conf

Plunker 2

答案 1 :(得分:0)

如果您需要从列表中过滤orderItem,请将其删除到此列表中。

您应该有3个列表:

  • allItems(将所有项目存储在某处)
  • 的OrderItems
  • itemsInSelect

当您从itemsInSelect中选择一个项目时,将其添加到orderItems并从itemsInSelect中删除它。

你想要的吗?