问题描述
我只是试图找到有关catcomplete的文档.我需要有关如何使用_renderItem的手册.我发现了这个 http://jqueryui.com/autocomplete/#categories ,但似乎没有提及关于那只是_renderMenu
I just tried to find documentation for catcomplete. I need manual for how to use _renderItem. I have found this http://jqueryui.com/autocomplete/#categories but seems there is no mention about that only just example for _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
is just an example and unfortunately not a part of jQuery UI, so there is no documentation for _renderItem
or renderMenu
. Think of this as a part of the jQuery source code. However the effect can very easily be reproduced from the source code.
要使用catcomplete,我们只需确保将label
和category
值都传递给catcomplete
,如下所示:
To use catcomplete, we need to simply ensure that both a label
and category
value are passed to catcomplete
as demonstrated:
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" }
];
以空白字符串作为类别的项目将不放入类别,而与标准自动完成一样保留.那些指定类别的用户将在该类别下进行子菜单.
Items with a blank string as a category will be not be put into a category and left as with the standard autocomplete. Those given a category will be sub-menued under that category.
在这里拨弄(以jQuery示例为例)
Fiddle here (of the jQuery example)
要为每个项目添加一个类,您只需在catcomplete
小部件中的最后一行代码的末尾附加.addClass(item.category)
:
To add a class to each item you can simply append .addClass(item.category)
to the end of the last line of code in the catcomplete
widget:
that._renderItemData( ul, item ).addClass(item.category);
这篇关于catcomplete文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!