jQuery UI autocomplete - that._renderItemData is not a function

丶灬走出姿态 提交于 2019-12-24 16:34:20

问题


I took the simple categories example of jQuery UI Autocomplete and integrated it in my application. When I started typing in my search bar, I get the error "TypeError: that._renderItemData is not a function" in Firebug.

I also have a jQuery no conflict.

jQuery(document).ready(function($) {

$.widget( "custom.catcomplete", $.ui.autocomplete, {
    _renderMenu: function( ul, items ) {
        var that = this,
            currentCategory = "";
        $.each( items, function( index, item ) {
            if ( item.category != currentCategory ) {
                ul.append( "<li class='ui-autocomplete-category'>" + item.category + "</li>" );
                currentCategory = item.category;
            }
            that._renderItemData( ul, item );
        });
    }
});     

$(function() {
    var data = [
        { label: "anders", category: "" },
        { label: "andreas", category: "" },
        { label: "antal", category: "" },
        { label: "annhhx10", category: "Products" },
        { label: "annk K12", category: "Products" },
        { label: "annttop C13", category: "Products" },
        { label: "anders andersson", category: "People" },
        { label: "andreas andersson", category: "People" },
        { label: "andreas johnson", category: "People" }
    ];

    $( "#search" ).catcomplete({
        delay: 0,
        source: data
    });

});

I think this is because of the conflict. So I tried replacing var that = this with

 var that = $(this)

and

var that = jQuery(this)

But both option is throwing the same error. How to resolve this conflict?


回答1:


Categories is new to jQuery UI 1.9. I was having 1.8.3.

Using the latest 1.9.2 jQuery JS fixed the problem.



来源:https://stackoverflow.com/questions/14180016/jquery-ui-autocomplete-that-renderitemdata-is-not-a-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!