Я пытаюсь получить итоговое значение списка из примера автозаполнения с категориями, и я не могу заставить его работать, как в других примерах.Я должен делать что-то глупое.
$.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 + "</li>" );
currentCategory = item.category;
}
self._renderItem( ul, item );
});
},
/* I ADDED THIS */
select: function(event, ui){<br>
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" }
];</p>
<code> $( "#search" ).catcomplete({
delay: 0,
source: data
});
});
</script>
</code>