jQuery UI自动完成 - that._renderItemData不是一个函数

时间:2013-01-06 06:45:24

标签: jquery jquery-ui jquery-ui-autocomplete

我使用了jQuery UI Autocomplete的简单categories example并将其集成到我的应用程序中。当我开始在搜索栏中输入内容时,我在Firebug中收到错误“TypeError:that._renderItemData不是函数”

我也有一个jQuery没有冲突。

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
    });

});

我认为这是因为冲突。所以我尝试用

替换var = this
 var that = $(this)

var that = jQuery(this)

但是这两个选项都抛出相同的错误。如何解决这个冲突?

1 个答案:

答案 0 :(得分:5)

类别是jQuery UI 1.9的新功能。我有1.8.3。

使用最新的1.9.2 jQuery JS解决了这个问题。