jQuery自动完成数据未定义错误 [英] jQuery autocomplete data undefined error
问题描述
我正在使用jquery v 2.0.0和jquery ui 1.10.3
I am using jquery v 2.0.0 and jquery ui 1.10.3
以下是我的jQuery UI自动完成代码:
Following is my jquery ui autocomplete code:
$nameField.combobox({
source: people,
buttonSelector: '.toggleList',
focus: function () {
return false;
},
select: function (event, ui) {
$nameField.val(ui.item.name).data({
id: ui.item.id,
name: ui.item.name,
birthdate: ui.item.birthdate
});
return false;
}
}).data('ui-autocomplete')._renderItem = function (ul, item) {
if (!_.include(self.idArr, item.id)) {
return $('<li></li>').data('ui-autocomplete-item', item).append('<a>' + item.name + '</a>').appendTo(ul);
}
};
这在旧版本的jquery中运行良好.但是升级后,当我单击.toggleList
按钮时,它将第一次打开,还有另一个按钮可将所选名称添加到div中.之后,当我单击`.toggleList'组合选择器时,自动完成功能不会打开.它给了我以下错误:
This was working perfectly in older version of jquery. But after the upgrade, when I click the .toggleList
button, it opens the first time and there's another button to add the selected name to a div. After that when I click the `.toggleList' combo selector, the autocomplete is not opening. It gives me the following error:
Uncaught TypeError: Cannot call method 'data' of undefined jquery.ui.autocomplete.js?1376892069:527
有人遇到这样的问题吗?我尝试了其他stackoverflow线程中提到的几个修复程序,但没有一个对我有用.
Anyone came across any issues like this? I tried several fixes mentioned in other stackoverflow threads, but none of them are working for me.
希望有人可以帮助我修复此错误
Hope someone could help me to fix this bug
谢谢
推荐答案
我找到了解决方案!
有人认为"ui-autocomplete"是错误的,因此他们使用"autocomplete"或"uiAutocomplete",但这是错误的.实际上,"ui-autocomplete"是执行此操作的正确方法.
I found the solution!
Somepeople think that "ui-autocomplete" is wrong, so them uses "autocomplete" or "uiAutocomplete", but that is wrong. Actually, "ui-autocomplete" is the right way to do this.
我遇到了同样的问题,并且和一位朋友一起发现了此代码的问题.相反:
I have the same issue you have, and I find with a friend the problem of this code. Instead:
.data('ui-autocomplete')._renderItem = function (ul, item) {
if (!_.include(self.idArr, item.id)) {
return $('<li></li>').data('ui-autocomplete-item', item).append('<a>' + item.name + '</a>').appendTo(ul);
}
};
使用:
._renderItem = function (ul, item) {
if (!_.include(self.idArr, item.id)) {
return $('<li></li>').data('ui-autocomplete-item', item).append('<a>' + item.name + '</a>').appendTo(ul);
}
};
我认为组合框和自动完成功能会返回一个数据('ui-autocomplete'),因此,如果您输入.data('ui-autocomplete'),您将执行以下操作:
I think combobox and autocomplete returns a data('ui-autocomplete'), so if you type .data('ui-autocomplete') you're doing something like:
.data('ui-autocomplete').data('ui-autocomplete')
怎么了....嗯,实际上我不知道为什么这不起作用以及为什么没有这个作用,但是请相信我,删除.data('ui-autocomplete')并感到高兴!
What's wrong....well, actually I don't know why this don't work and why without this works, but trust me, delete .data('ui-autocomplete') and be happy!
这篇关于jQuery自动完成数据未定义错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!