我采用了 jQuery UI Autocomplete 的简单类别示例并将其集成到我的应用程序中。当我开始在搜索栏中输入时,我在 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 that = this 替换为
var that = $(this)
和
var that = jQuery(this)
但是这两个选项都抛出了同样的错误。如何解决这个冲突?