簡體   English   中英

無法檢索,重置或更新select2選項

[英]Can't retrieve, reset or update select2 options

請參閱以下jsfiddle: https ://jsfiddle.net/L1tns1yh/1/

首先,它無法檢索正確的.select2('data')

然后,單擊按鈕不會重置選項,嘗試了我在互聯網上找到的其他方法...

請更新如下所示的按鈕點擊事件,

$button.click(function () {
  $select.empty();
});

您可以嘗試以下方法,我不太喜歡這種解決方案,但是如果您創建一個新的select2,它就可以工作:

$button.click(function () {
  $('#select').select2('destroy').empty().select2({allowClear: true,
  placeholder: 'Placeholder...'});
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM