2016-02-23 40 views
0

我试图使用选择2插件(4.0.2.rc1)的新版本,但我有allowClear行动的问题。jQuery的选择2插件allowClear行为

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

与版本3.5.2“清除”行动效果很好,但这个版本时,我点击x清洁的选择将干净的选择,但即使打开下拉菜单

enter image description here

我怎样才能解决这个问题? 谢谢

回答

0

对于那些有兴趣,这是解决问题的办法,希望它会在插件的新版本纠正问题。

$('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'); 
    } 
});