我正在尝试使用类别示例从自动完成中获取结果列表框值,并且我无法像其他示例那样使其工作。我必须做些蠢事。
$.widget( "custom.catcomplete", $.ui.autocomplete, { _renderMenu: function( ul, items ) { var self = this, currentCategory = ""; $.each( items, function( index, item ) { if ( item.category != currentCategory ) { ul.append( "" + item.category + "" ); currentCategory = item.category; } self._renderItem( ul, item ); }); }, /* I ADDED THIS */ select: function(event, ui){
alert(ui.item.value); } }); $(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 }); }); </script>
答案 0 :(得分:0)
我明白了。我需要把它放在这里:
$("#search").catcomplete({
delay: 0,
source: data,
select: function(event, ui){
alert(ui.item.label);
}
});