Select2 3.4.5如果选择了其下的所有选项,则不显示optgroup

时间:2018-02-28 10:31:33

标签: jquery jquery-select2

有没有办法删除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标题应该消失

0 个答案:

没有答案