我只是试着查找catcomplete的文档。我需要如何使用_renderItem的手册。我找到了这个http://jqueryui.com/autocomplete/#categories,但似乎没有提到这一点,只是_renderMenu的例子
_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 );
});
}发布于 2012-12-04 18:39:56
catcomplete只是一个例子,不幸的是,它不是jQuery UI的一部分,所以没有关于_renderItem或renderMenu的文档。可以将其视为jQuery源代码的一部分。然而,这种效果可以很容易地从源代码中复制出来。
要使用catcomplete,我们只需确保label和category值都传递给catcomplete,如下所示:
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" }
];具有空白字符串作为类别的项目将不会被放入类别中,并与标准自动完成一样保留。那些给定了类别的将在该类别下显示。
Fiddle here ( jQuery示例的)
要向每个项目添加一个类,只需将.addClass(item.category)附加到catcomplete小部件中最后一行代码的末尾:
that._renderItemData( ul, item ).addClass(item.category);https://stackoverflow.com/questions/13698310
复制相似问题