Select2 清除另一个 optgroup 中的项目

Select2 clear items in another optgroup

optgroup 中选择一个元素时,我希望取消选择其他 optgroup 中的元素。这是 fiddle

https://jsfiddle.net/zfmr0std/

$("#block_house_suggest").select2().on("select2-selecting", function(e) {
    var selected = $("#block_house_suggest [value='"+e.val+"']");
    var opts = selected.parent().children();
    var selected_array = [];

    selected.prop('selected',true);

    for (i = 0; i < opts.length; i++) {
        if($(opts[i]).prop('selected')){
            selected_array.push($(opts[i]).val());
        }
    }
    $("#block_house_suggest").select2('data', selected_array);
});
var selected = '';
   $("#block_house_suggest").select2()
       .on("select2-selecting", function(e) {
           selected = e.val;
       })
       .on("change", function(e) {

           var selected_list = e.val;
           var opts = $("#block_house_suggest [value='"+selected+"']").parent().children();
           var opts_array = [];

           for (i = 0; i < opts.length; i++) {
               opts_array.push($(opts[i]).val());
           }

           selected_list = selected_list.filter(function(n) {
               return opts_array.indexOf(n) != -1;
           });

           $("#block_house_suggest").select2('val', selected_list);
           e.preventDefault();
       });