由于我从jqueryui 1.8.1转为1.10.x,我意识到我的自定义项目渲染器不再工作了:
Uncaught TypeError: Cannot set property '_renderItem' of undefined
新的jqueryui版本有什么区别?
这里我的代码:
$("#lexicon-search-input")
.autocomplete({
...
}).data("autocomplete")._renderItem = customItemRenderer;
这是在jqueryui 1.8.1上工作,但不在1.10.3。
还有一件事:我使用多个自动填充字段。因此,我无法在全球设置。例如,$ .ui.autocomplete.prototype._renderItem = customrenderItem将起作用,但会影响我的所有自动完成。
解决方法
使用ui-autocomplete代替应该解决你的问题。
$("#lexicon-search-input")
.autocomplete({
...
}).data("ui-autocomplete")._renderItem = customItemRenderer;
有关如何使用_renderItem(特别是源代码)的教程,请参阅documentation
如果要为多个autocompletes创建_renderItem函数,classClassClass仅在createevent中使用
$('.yourClass').autocomplete({
create: function() {
$(this).data('ui-autocomplete')._renderItem ....
}
});
看到另一个answer我关于这个话题。