本文介绍了为什么会出现这种JS错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我得到这个JS错误:
jQuery的-1.5.1.min.js:16Uncaught类型错误:无法设置属性_renderItem未定义
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
和从这个code在我的application.js文件中的jQuery UI的自动完成插件是:
。数据(自动完成)._ renderItem =功能(UL,项目){
返回$(<立GT;< /李>中)
。数据(item.autocomplete项)
.append(&所述a取代;+ item.topic.name +&下; / A>中)
.appendTo(微升);
};
我得到这个code每当我加载一个页面,没有文本字段的自动完成code的作用。为什么和如何才能摆脱这种错误的?
我想指出,虽然我得到这个错误,我的应用程序正常工作。应我甚至会担心这个错误?
解决方案
$(...)。数据(自动完成)
是不确定的,你不能设置未定义的属性。尝试:
VAR OBJ = $(...)的数据(自动完成)。
OBJ和放大器;&安培; (obj._renderItem =函数(){
...
});
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
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错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!