gpt4 book ai didi

jquery - 如何处理 "The select2(' destroy') 方法在不使用 Select2 的元素上调用”

转载 作者:行者123 更新时间:2023-12-03 22:28:39 27 4
gpt4 key购买 nike

我正在使用 ui-select2 并尝试通过单击编辑按钮打开新页面。我看到一些奇怪的问题。当我第一次打开新页面时,它打开得很好,但是当我取消它并再次打开同一页面时,通过单击编辑,它给了我以下错误:

select2.full.min.js:3 The select2('destroy') method was called on an element that is not using Select2
angular.js:13708 TypeError: Cannot read property 'destroy' of undefined
at n.a.fn.select2 (select2.full.min.js:3)
at HTMLSelectElement.<anonymous> (select2.js:175)
at HTMLSelectElement.dispatch (jQuery-2.1.4.min.js:3)
at HTMLSelectElement.r.handle (jQuery-2.1.4.min.js:3)
at Object.trigger (jQuery-2.1.4.min.js:3)
at n.triggerHandler (jQuery-2.1.4.min.js:3)
at Function.pa.fn.on.pa.cleanData (angular.js:1865)
at n.remove (jQuery-2.1.4.min.js:3)
at angular.js:5504
at Object.push (angular.js:5085)

通过阅读此消息,似乎我必须定义销毁方法,但我不知道如何在 Controller 中定义销毁方法以及如何调用取消按钮(取消方法)调用。以下是选择的代码片段:

<select ui-select2 class="form-control input-lg" ng-model="cityId" ng-change="loadLocality()">
<option ng-repeat="city in cities|orderBy:'name'|filter:'ACTIVE':true" value="{{city.id}}">{{city.name}}</option>
</select>

最佳答案

对 select2 使用简单的检查,如下所示:

if ($('select').data('select2')) {
$('select').select2('destroy');
}

我在 GitHub Issue 中找到了代码 https://github.com/aldeed/meteor-autoform-select2/issues/44

关于jquery - 如何处理 "The select2(' destroy') 方法在不使用 Select2 的元素上调用”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38797207/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com