我只是想找到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 );
});
}
最佳答案
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);
关于jquery-ui - catcomplete 的文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13698310/