2016-02-23 39 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'); 
    } 
});