为什么我会收到这个 JS 错误? [英] Why am I getting this JS error?
本文介绍了为什么我会收到这个 JS 错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到此 JS 错误:
I get this JS error:
jquery-1.5.1.min.js:16Uncaught TypeError: Cannot set property '_renderItem' of undefined
d.d.extend._Deferred.f.resolveWithjquery-1.5.1.min.js:16
d.d.extend.readyjquery-1.5.1.min.js:16
d.c.addEventListener.A
它来自我的 application.js 文件中 jquery UI 自动完成插件的代码:
and it's from this code for the jquery UI autocomplete plugin in my application.js file:
.data( "autocomplete" )._renderItem = function( ul, item ) {
return $( "<li></li>" )
.data( "item.autocomplete", item )
.append( "<a>" + item.topic.name + "</a>" )
.appendTo( ul );
};
每当我加载没有自动完成代码所作用的文本字段的页面时,我都会收到此代码.为什么以及如何消除此错误?
I get this code whenever I load a page that does NOT have the text field that the autocomplete code is acting on. Why and how can I get rid of this error?
我想指出,虽然我收到此错误,但我的应用程序运行正常.我应该担心这个错误吗?
I'd like to note that although I am getting this error, my application is working normally. Should I even be worrying about this error?
推荐答案
$(...).data('autocomplete')
是未定义的,您不能设置未定义的属性.试试:
is undefined, and you can't set a property of undefined. try:
var obj = $(...).data('autocomplete');
obj && (obj._renderItem = function(){
...
});
这篇关于为什么我会收到这个 JS 错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文