สรุป :
ฉันใช้คำสั่ง angularjs-dropdown-multiselect
ข้อมูลอ้างอิง : การเลือกหลายรายการแบบเลื่อนลงของ AngularJS
ปัญหาที่กำลังเผชิญ :
ปัญหาที่ 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 แต่ไม่ประสบความสำเร็จใดๆ
ความช่วยเหลือใด ๆ ในประเด็นทั้งสองทันทีจะได้รับการชื่นชมอย่างมาก ขอบคุณ