0
我有easyui combobox,它是多選的。我限制了可以選擇的項目數量,因此如果您嘗試選擇超過限制,它會向用戶發出警報,並且不允許選擇項目。這是我的代碼。限制easyui combobox中的選擇數量
$("#assessment_content_items_select_standards").combobox({
data: $rootScope.assessmentItemsFilters.selectedStandards,
valueField: 'value',
textField: 'label',
multiple: true,
onSelect: function (standard)
{
var selectedStandardsCount = 0;
angular.forEach($rootScope.assessmentItemsFilters.selectedStandards, function (stan) {
if (stan.selected == true) {
selectedStandardsCount++;
}
});
if (selectedStandardsCount >= 25) {
alert("You have reached the maximum selected standards allowed of 25");
}
else {
standard.selected = true;
}
},
onUnselect: function (standard) {
standard.selected = false;
}
});
在ONSELECT方法,我得到了所選的計數,如果它更多的25只是做一個警告,它不設置選擇爲true該選擇。
我遇到的問題是即使數據顯示爲選中,UI仍顯示爲選中項:false。我試過以下取消選擇,但我沒有看到任何區別。
standard.selected = false
$("#assessment_content_items_select_standards").combobox('unselect', standard);
我的問題是如何阻止選項被選中,或者有更好的方法來限制下拉菜單嗎?