需要在 angular ui select 中添加多个过滤器
Need to add multiple filter in 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"]
我还需要按 filter: $select.search
以及 orderItem 对其进行过滤。如何在ui-select中添加这个自定义过滤器?
在下拉菜单中,我应该只得到 a、b,我应该过滤 c
尝试类似的东西
var app = angular.module('demo', ['ui.select']);
app.controller('DemoCtrl', function($scope) {
$scope.itemDetails = ['a','b','c'];
$scope.orderItem = {};
$scope.orderItem.items = ['a','b']; // by default selected items
});
在您看来
<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;
};
});
查看:
<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>
如果您需要从列表中筛选出您的 orderItem
,请将它们删除到此列表中。
您应该有 3 个列表:
- allItems(将所有项目存储在某处)
- 订单商品
- itemsInSelect
当您 select itemsInSelect 中的一项时,将其添加到 orderItems 并将其从 itemsInSelect 中删除。
是你想要的吗?
需要在 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"]
我还需要按 filter: $select.search
以及 orderItem 对其进行过滤。如何在ui-select中添加这个自定义过滤器?
在下拉菜单中,我应该只得到 a、b,我应该过滤 c
尝试类似的东西
var app = angular.module('demo', ['ui.select']);
app.controller('DemoCtrl', function($scope) {
$scope.itemDetails = ['a','b','c'];
$scope.orderItem = {};
$scope.orderItem.items = ['a','b']; // by default selected items
});
在您看来
<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;
};
});
查看:
<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>
如果您需要从列表中筛选出您的 orderItem
,请将它们删除到此列表中。
您应该有 3 个列表:
- allItems(将所有项目存储在某处)
- 订单商品
- itemsInSelect
当您 select itemsInSelect 中的一项时,将其添加到 orderItems 并将其从 itemsInSelect 中删除。
是你想要的吗?