Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
688 views
in Technique[技术] by (71.8m points)

jquery ui - jQueryUI version 1.10 autocomplete - how to set _renderItem?

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 

What is different in new jqueryui versions?

Here my code:

$("#lexicon-search-input")
        .autocomplete({
        ...
        }).data("autocomplete")._renderItem = customItemRenderer;

This was working on jqueryui 1.8.1 but doesn't on 1.10.3.

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Using ui-autocomplete instead should solve your issue.

$("#lexicon-search-input")
    .autocomplete({
    ...
    }).data("ui-autocomplete")._renderItem = customItemRenderer;

See the documentation for a tutorial on how to use _renderItem (especially the source code)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...