有没有办法删除optgroup标题,如果它下面没有选项可供选择(所有选项都已被选中)?
我的代码是:
formSelectElement.select2({
placeholder: 'Type to search for a user...',
minimumInputLength: 3,
query: query,
multiple: true,
closeOnSelect: false,
maximumSelectionSize: formSelectElement.data('primary'),
initSelection: setAssigneeInitSelection
}).on("select2-selecting", function(e) {
if (e.val == 0) {
e.preventDefault()
return;
}
});
数据是:
var data = {results: []};
var teams = {id: 0, text: 'Teams', children: [some children here]};
var users = {id: 0, text: 'Users', children: [some children here]};
data.results.push(teams);
data.results.push(users);
所以我基本上想要的是在选择Teams下的每个选项后,Teams标题应该消失