AngularJS Dropdown Multiselect - 每个选项搜索自定义模板。
我发现我的查询解决方案将使用AngularJS Dropdown Multiselect文档的上述url,但如果我使用下面的代码,则不反映我的应用程序视图:
$scope.example19settings = {
template: '<b>{{option.name}}</b>'
};
我想通过添加一个计数来实现它:
$scope.example19settings = {
template: '<b>{{option.name}}({{option.count}})</b>'
};
有任何建议或缺失的链接吗?
$scope.extraSettings = {
settings: {
selectedToTop: true,
styleActive: true,
/*template: '<b>{{option.label}}</b>'*/
scrollable: true,
scrollableHeight: 200,
showEnableSearchButton: true
}
};
答案 0 :(得分:5)
请在下面找到工作解决方案。以下是我所做的改变。
将miltiselect
库更改为this(最新)
将'angularjs-dropdown-multiselect'
添加为我的主应用模块
MainCtrl
,将其分配给模板$scope.example19model = [];
添加了额外的属性($scope
)以保留所选选项。请告诉我,如果这适合您:)
var app = angular.module('app', ['angularjs-dropdown-multiselect']);
app.controller('MainCtrl', function($scope) {
$scope.example19model = [];
$scope.example19data = [{
id: 1,
name: "David",
count: 20
}, {
id: 2,
name: "Jhon",
count: 30
}, {
id: 3,
name: "Lisa",
count: 40
}, {
id: 4,
name: "Nicole",
count: 50
}, {
id: 5,
name: "Danny",
count: 60
}];
$scope.example19settings = {
template: '<b>{{option.name}} ({{option.count}})</b>'
};
})
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.5/angular.js"></script>
<script src="https://rawgit.com/dotansimha/angularjs-dropdown-multiselect/master/dist/angularjs-dropdown-multiselect.min.js"></script>
<div ng-app="app">
<div ng-controller="MainCtrl">
<div ng-dropdown-multiselect="" options="example19data" selected-model="example19model" extra-settings="example19settings"></div>
{{example19model}}
</div>
</div>
答案 1 :(得分:1)
您可以使用select2库来帮助选择多个输入。
检查此link以获取实时演示。
<h3>Array of strings</h3>
<ui-select multiple ng-model="ctrl.multipleDemo.colors" theme="bootstrap" ng-disabled="ctrl.disabled" close-on-select="false" style="width: 300px;" title="Choose a color">
<ui-select-match placeholder="Select colors...">{{$item}}</ui-select-match>
<ui-select-choices repeat="color in ctrl.availableColors | filter:$select.search">
{{color}}
</ui-select-choices>
</ui-select>
<p>Selected: {{ctrl.multipleDemo.colors}}</p>