我想设计一个复选框的下拉列表,并使复选框可以多选。我使用了下面的代码,但是我无法进行多项选择,因为每次单击复选框时模板都会刷新,请提出一些建议吗?
{ <ul class="status-select" class="status-select" ng-if="$index == selectedFilterIndex">
<li ng-repeat="DataValue in filter.Data.Value">
<input type="checkbox" ng-click="OnDropDownSelectionChanged(filter,DataValue)">
{{DataValue.displayText}}
</li>
</ul>
}
答案 0 :(得分:16)
您可以使用 angularjs-dropdown-multiselect 等指令,您可以在互联网上轻松找到
以下是一些例子:
代码段:
var myApp = angular.module('exampleApp', ['angularjs-dropdown-multiselect']);
myApp.controller('appController', ['$scope',
function($scope) {
$scope.example13model = [];
$scope.example13data = [{
id: 1,
label: "David"
}, {
id: 2,
label: "Jhon"
}, {
id: 3,
label: "Lisa"
}, {
id: 4,
label: "Nicole"
}, {
id: 5,
label: "Danny"
}];
$scope.example13settings = {
smartButtonMaxItems: 3,
smartButtonTextConverter: function(itemText, originalItem) {
if (itemText === 'Jhon') {
return 'Jhonny!';
}
return itemText;
}
};
}
]);
&#13;
div, h1, a {
padding: 5px;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.20/angular.min.js"></script>
<link href="https://bootswatch.com/slate/bootstrap.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.10.0/lodash.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angularjs-dropdown-multiselect/1.2.0/angularjs-dropdown-multiselect.min.js"></script>
<h2>
Example of sytled angularjs-dropdown-multiselect
</h2>
<a href="http://dotansimha.github.io/angularjs-dropdown-multiselect/#/">Source documentation</a>
<div ng-app="exampleApp" ng-controller="appController">
<div ng-dropdown-multiselect="" options="example13data" selected-model="example13model" extra-settings="example13settings"></div>
</div>
&#13;
答案 1 :(得分:7)
我发现使用auto-close="outsideClick"
使用Angular Directives for Bootstrap的简单解决方法,代码应如下所示:
<div class="dropdown" uib-dropdown auto-close="outsideClick" on-toggle="toggled(open)">
<a class="btn btn-primary" uib-dropdown-toggle>Toggle</a>
<ul class="dropdown-menu status-select" class="status-select" ng-if="$index == selectedFilterIndex" uib-dropdown-menu>
<li ng-repeat="DataValue in filter.Data.Value">
<div class="checkbox">
<label>
<input type="checkbox" ng-click="OnDropDownSelectionChanged(filter,DataValue)">
{{DataValue.displayText}}
</label>
</div>
</li>
</ul>
</div>
答案 2 :(得分:2)
您可以选择Angular Material Design Library