Javascript 值树的JQuery文本输入自动完成
大家 我有一个文本输入,其内容应限制为一组值。这些值的形式为dependency1、dependency2、dependency3,因此它们形成一个树。我想提供一个智能自动完成这个领域,知道这个结构。例如,结构如下所示:Javascript 值树的JQuery文本输入自动完成,javascript,jquery-plugins,Javascript,Jquery Plugins,大家 我有一个文本输入,其内容应限制为一组值。这些值的形式为dependency1、dependency2、dependency3,因此它们形成一个树。我想提供一个智能自动完成这个领域,知道这个结构。例如,结构如下所示: Engineering Electric Communication Power Electronic Computation Control Economy Economy Accounting Education Basi
Engineering
Electric
Communication
Power
Electronic
Computation
Control
Economy
Economy
Accounting
Education
Basic
Language
English
French
Sciences
Math
Physics
因此,一旦用户输入了足够的字母,第一个依赖项就应该完成,它应该准备好自动完成下一个依赖项。如果一些选项出现在弹出窗口中,它们应该仅限于我们所依赖的项,而不是所有树
您知道有任何jQuery(或其他)库提供类似的功能吗
提前感谢。这不是应该问的问题类型,但是有一个名为jQuery UI的插件,它依赖于jQuery,内置了一个自动完成插件。看看:
这不完全是应该问的问题类型,但是有一个名为jQuery UI的插件,它依赖于jQuery,内置了一个自动完成插件。看看:
在另一次关于值分组的搜索中发现了一个小提琴。再多做一点-我认为这会很好-我只有一个级别的分组,但我认为可以添加更多: HTML: jQuery:
$.widget( "custom.catcomplete", $.ui.autocomplete, {
_create: function() {
this._super();
this.widget().menu( "option", "items", "> :not(.ui-autocomplete-category)" );
},
_renderMenu: function( ul, items ) {
var that = this,
currentCategory = "";
$.each( items, function( index, item ) {
var li;
if ( item.category != currentCategory ) {
ul.append( "<li class='ui-autocomplete-category " + item.category + "'>" + item.category + "</li>" );
currentCategory = item.category;
}
li = that._renderItemData( ul, item );
if ( item.category ) {
li.attr( "aria-label", item.category + " : " + item.label );
}
});
},
_renderItem: function( ul, item ) {
return $( "<li>" )
.addClass(item.category)
.attr( "data-value", item.value )
.append( $( "<a>" ).text( item.label ) )
.appendTo( ul );
}
});
$(function() {
var data = [
{ label: "annhhx10", category: "Products" },
{ label: "annk K12", category: "Products" },
{ label: "annttop C13", category: "Products" },
{ label: "bannttop C13", category: "Products" },
{ label: "cannttop C13", category: "Products" },
{ label: "dannttop C13", category: "Products" },
{ label: "eannttop C13", category: "Products" },
{ label: "fannttop C13", category: "Products" },
{ label: "gannttop C13", category: "Products" },
{ label: "hannttop C13", category: "Products" },
{ label: "iannttop C13", category: "Products" },
{ label: "jannttop C13", category: "Products" },
{ label: "anders andersson", category: "People" },
{ label: "andreas andersson", category: "People" },
{ label: "andreas johnson", category: "People" },
{ label: "bandreas johnson", category: "People" },
{ label: "candreas johnson", category: "People" },
{ label: "dandreas johnson", category: "People" },
{ label: "eandreas johnson", category: "People" },
{ label: "fandreas johnson", category: "People" },
{ label: "gandreas johnson", category: "People" },
];
$( "#search" ).catcomplete({
delay: 0,
source: data
});
});
$.widget(“custom.catcomplete”,$.ui.autocomplete{
_创建:函数(){
这个;
this.widget()菜单(“选项”,“项目”,“>:非(.ui自动完成类别)”);
},
_renderMenu:功能(ul,项目){
var=这个,
currentCategory=“”;
$。每个(项目、功能(索引、项目){
李华;
如果(item.category!=当前类别){
ul.追加(“
$.widget(“custom.catcomplete”,$.ui.autocomplete{
_创建:函数(){
这个;
this.widget()菜单(“选项”,“项目”,“>:非(.ui自动完成类别)”);
},
_renderMenu:功能(ul,项目){
var=这个,
currentCategory=“”;
$。每个(项目、功能(索引、项目){
李华;
如果(item.category!=当前类别){
ul.追加(“