问题
AngularJS Dropdown Multiselect -- Search Custom template per option.
I have found the solution of my query will be using the above url of the documentation of AngularJS Dropdown Multiselect but if I am using the below code, it doesn't reflect on the view of my application:
$scope.example19settings = {
template: '<b>{{option.name}}</b>'
};
I want to acheive it by adding a count:
$scope.example19settings = {
template: '<b>{{option.name}}({{option.count}})</b>'
};
Any suggestions or missing links?
$scope.extraSettings = {
settings: {
selectedToTop: true,
styleActive: true,
/*template: '<b>{{option.label}}</b>'*/
scrollable: true,
scrollableHeight: 200,
showEnableSearchButton: true
}
};
回答1:
Please find working solution below. Following are the changes I have done.
Change the reference if
miltiselect
library to this (latest)Added the
'angularjs-dropdown-multiselect'
as dependency to my main app module- Created a controller
MainCtrl
, assigned it to the template - Added an extra property (
$scope.example19model = [];
) to$scope
for holding selected options.
Let me know, if this works for you :)
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>
回答2:
You can use select2 library which helps to select multiple inputs.
Check this link for live demo.
<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>
来源:https://stackoverflow.com/questions/47260040/how-to-show-dropdown-values-with-count-using-angularjs-dropdown-multiselect