Error: cannot call methods on autocomplete prior to initialization; attempted to call method 'destroy'

痴心易碎 提交于 2019-12-19 17:38:48

问题


I am using ajax-solr. It works fine with jquery-ui-1.8.*.

But when I upgrade it to jquery-1.10.* it gives me this exception:

cannot call methods on autocomplete prior to initialization; attempted to call method 'destroy'


回答1:


I got the answer to it in the initialization of autocomplete widget...just add

$(this.target).find('input').autocomplete();

This will initialize the autocomplete widget this happened because in 1.10.* .Jquery has added error messages for usage of functions without proper initialization whereas it was not there in previous versions.




回答2:


If you want to make sure the autocomplete widget is destroyed, you can check if it was actually initialized by inspecting the CSS classes of the target element, e.g.

if ($target.hasClass('ui-autocomplete')) {
    $target.autocomplete('destroy')
}



回答3:


I was getting similar error regarding the widget call,

Inside the autocomplete initialization, we were calling its widget function, that was creating the console error.

In test-result.component.ts,

(<any> window).$(testelementId).autocomplete({
……..
(<any> window).$(this).autocomplete('widget').css('width', '100%');
…..
})

So, the easiest fix was to remove that particular call or place it after the initialization and test if that breaks any style. For me, removing the widget call is not doing any harm, so went ahead with that.



来源:https://stackoverflow.com/questions/21549126/error-cannot-call-methods-on-autocomplete-prior-to-initialization-attempted-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!