jQueryUI 1.10版自动完成功能-如何设置_renderItem? [英] jQueryUI version 1.10 autocomplete - how to set _renderItem?

查看:99
本文介绍了jQueryUI 1.10版自动完成功能-如何设置_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事件

If you want to create the _renderItem function for multiple autocompletes with class yourClass just use it in the createevent

$('.yourClass').autocomplete({
    create: function() {
        $(this).data('ui-autocomplete')._renderItem ....
    }
});

有关该主题,另外一个我的答案.

See another answer of me on that topic.

这篇关于jQueryUI 1.10版自动完成功能-如何设置_renderItem?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆