1.报错信息
VM3333:21 Uncaught query function not defined for Select2 s2id_autogen1
2.我们使用select2时,当option需要动态渲染的时候,我们就需要在更新完option数据后,重新初始化select2,这个时候如果我们在初始化之前没有先销毁select2,就会上述报错
//销毁
var $select = $('.yourSelect2');
var instance = $select.data('select2');
if (instance) {
$select.select2('destroy').empty();
}
//更新option
......
//重新初始化
$select.select2();
本文解决在使用Select2插件时,动态更新Option后重新初始化遇到的Uncaught query function not defined错误。文章详细介绍了如何在更新数据前先销毁Select2实例,再进行数据更新和重新初始化的过程。
1225

被折叠的 条评论
为什么被折叠?



