摘要:
我正在使用angularjs-dropdown-multiselect指令。
参考: AngularJS Dropdown Multiselect
面临的问题:
问题1:
我想使用onItemSelect
&用户从下拉列表中选择或取消选择选项时发生onItemDeselect
个事件。
我成功配置它们,但问题是如果没有选择任何选项,这些事件也会频繁执行。
HTML
<div ng-dropdown-multiselect="" options="listClientCompany" selected-model="selectedClients" extra-settings="clientSelectionSettings" translation-texts="translations" events="onItemSelect(selectedClients);onItemDeSelect(selectedClients)"></div>
控制器:
$scope.selectedClients = [];
$scope.clientSelectionSettings = {idProp: '_id',displayProp:'name',externalIdProp : "_id",enableSearch:false,scrollableHeight: '200px',scrollable:true};
$scope.translations = {buttonDefaultText: 'Select'};
$scope.onItemSelect = function(item) {
console.log(item); // execute multiple times on page load also without selecting any option from the dropdown.
}
屏幕截图:
我也尝试过这里定义的解决方案:
https://github.com/dotansimha/angularjs-dropdown-multiselect/issues/39。但没有取得任何成功。
问题2:
当我从控制器中删除$scope.selectedClients = [];
时,它在控制台中给出了这个错误。
Error: [$interpolate:interr] Can't interpolate: {{getButtonText()}}
TypeError: Cannot read property 'length' of undefined
http://errors.angularjs.org/1.2.19/$interpolate/interr?p0=%7B%7BgetButtonTe…%A0&p1=TypeError%3A%20Cannot%20read%20property%20'length'%20of%20undefined
at http://0.0.0.0:9000/bower_components/angular/angular.js:78:12
at Object.$interpolate.fn (http://0.0.0.0:9000/bower_components/angular/angular.js:8756:26)
at Scope.$digest (http://0.0.0.0:9000/bower_components/angular/angular.js:12426:40)
at Scope.$apply (http://0.0.0.0:9000/bower_components/angular/angular.js:12699:24)
at done (http://0.0.0.0:9000/bower_components/angular/angular.js:8287:45)
at completeRequest (http://0.0.0.0:9000/bower_components/angular/angular.js:8499:7)
at XMLHttpRequest.xhr.onreadystatechange (http://0.0.0.0:9000/bower_components/angular/angular.js:8438:11) angular.js:9959
我也尝试过这里定义的解决方案:
https://github.com/dotansimha/angularjs-dropdown-multiselect/issues/22 但没有取得任何成功。
对这两个问题的任何直接帮助都将非常值得注意。感谢
答案 0 :(得分:0)
总是将数组发送到该函数 你应该这样做
$scope.selectedClients = [];
$scope.selectedClient = {};
$scope.clientSelectionSettings = {idProp: '_id',displayProp:'name',externalIdProp : "_id",enableSearch:false,scrollableHeight: '200px',scrollable:true};
$scope.translations = {buttonDefaultText: 'Select'};
$scope.onItemSelect = function(item) {
//then you can push your object to the array
console.log(item); // execute multiple times on page load also without selecting any option from the dropdown.
}
和
<div ng-dropdown-multiselect="" options="listClientCompany" selected-model="selectedClient" extra-settings="clientSelectionSettings" translation-texts="translations" events="onItemSelect(selectedClient);onItemDeSelect(selectedClient)"></div>