Jquery select2 插件 allowClear 行为

Jquery select2 plugin allowClear behavior

我正在尝试使用新版本的 select2 插件 (4.0.2.rc1),但我对 allowClear 操作有疑问。

$('select').select2({
   theme: 'bootstrap',
   placeholder: '..',
   allowClear: true
});

对于 3.5.2 版本,"clear" 操作运行良好,但对于此版本,当我单击 x 清除选项时会清除选项,但甚至会打开下拉菜单

我该如何解决这个问题? 谢谢

对于那些感兴趣的人,这是问题的解决方案,希望它能在新版本的插件中解决问题。

$('select').select2({
   theme: 'bootstrap',
   placeholder: '..',
   allowClear: true
});

/* FIX */
var $el = $('select');
$el.on('select2:unselecting', function(e) {
   $el.data('unselecting', true);
}).on('select2:open', function(e) { // note the open event is important
   if ($el.data('unselecting')) {
       $el.removeData('unselecting'); // you need to unset this before close
            $el.select2('close');
   }
});