[英]Limit the number of selections in easyui combobox
我有多个选择的easyui组合框。 我对可以选择的项目数设置了限制,因此,如果您尝试选择的数量超出限制,则会提醒用户并且不允许选择该项目。 这是我的代码。
$("#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,它只会发出警报,并且不会将该选择的selected设置为true。
我遇到的问题是,即使数据显示为选中状态,UI仍将项目显示为选中状态:false。 我尝试了以下取消选择的选项,但没有区别。
standard.selected = false
$("#assessment_content_items_select_standards").combobox('unselect', standard);
我的问题是如何停止选择选项,或者是否有更好的方法限制下拉菜单?
试试这个:
$('#assessment_content_items_select_standards').combobox({
onSelect: function (standard) {
var count = $("div.combobox-item-selected").length;
if (count > 25) {
alert("You can only choose 25.");
$('#assessment_content_items_select_standards').combobox('unselect', standard. value);
}
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.