Ume*_*ola 8 jquery jquery-select2
在我的select2选择中,我需要在文档准备好后附加li,并在追加后,如何重新初始化select2.如果我一旦关闭并再次打开选择,附加的数据是可选择的,但不是我追加的时候.我怎样才能重新初始化它.
Miv*_*web 23
你必须销毁这些元素上的select2,然后重新初始化它.
$("select").select2("destroy").select2();
Run Code Online (Sandbox Code Playgroud)
感谢@Mivaweb 的上述回答 ^
所以如果我使用:
$("select").select2("destroy").select2();
Run Code Online (Sandbox Code Playgroud)
然后我遇到了以下问题,就像一些人在评论上面的答案时一样:
The select2('destroy') method was called on an element that is not using Select2
Run Code Online (Sandbox Code Playgroud)
但这并不意味着它不起作用,它确实有效,但需要稍微更新一下方法。
我的工作解决方案:
STEP1:销毁现有的 select2 实例
STEP2:更新选项或选择
STEP3:现在初始化新的 select2 实例
例如:
$(".select2me-filter").select2("destroy");
... Here do option updates you need
$(".select2me-filter").select2();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
19933 次 |
| 最近记录: |