jQueryUI 1.10 版自动完成 - 如何设置 _renderItem? [英] jQueryUI version 1.10 autocomplete - how to set _renderItem?
问题描述
自从我从 jqueryui 1.8.1 切换到 1.10.x 后,我意识到我的自定义项渲染器不再工作了:
Since I switched from jqueryui 1.8.1 to 1.10.x I realised that my custom item renderer doesn't work anymore:
Uncaught TypeError: Cannot set property '_renderItem' of undefined
新的 jqueryui 版本有什么不同?
What is different in new jqueryui versions?
这是我的代码:
$("#lexicon-search-input")
.autocomplete({
...
}).data("autocomplete")._renderItem = customItemRenderer;
这适用于 jqueryui 1.8.1,但不适用于 1.10.3.
This was working on jqueryui 1.8.1 but doesn't on 1.10.3.
还有一件事:我使用了多个自动完成字段.因此,我无法全局设置它.例如, $.ui.autocomplete.prototype._renderItem = customRenderItem 可以工作,但会影响我所有的自动完成.
One more thing: I use multiple autocomplete fields. Therefore, I can not set it globally. For instance, $.ui.autocomplete.prototype._renderItem = customRenderItem would work, but will affect all of my autocompletes.
推荐答案
改用 ui-autocomplete
应该可以解决您的问题.
Using ui-autocomplete
instead should solve your issue.
$("#lexicon-search-input")
.autocomplete({
...
}).data("ui-autocomplete")._renderItem = customItemRenderer;
有关如何使用 _renderItem
文档>(尤其是源代码)
See the documentation for a tutorial on how to use _renderItem
(especially the source code)
如果您想使用 yourClass
类为多个自动完成创建 _renderItem
函数,只需在 create
event
If you want to create the _renderItem
function for multiple autocompletes with class yourClass
just use it in the create
event
$('.yourClass').autocomplete({
create: function() {
$(this).data('ui-autocomplete')._renderItem ....
}
});
请参阅我关于该主题的另一个答案.
See another answer of me on that topic.
这篇关于jQueryUI 1.10 版自动完成 - 如何设置 _renderItem?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!