I\'m using the jquery ui autocomplete combobox, and it\'s working great but now i\'m getting a bit greedy. I would like to be able to add categories to it. The combobox is
as you can see in the jQueryUI docs, you have to customize the widget to do that
_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 );
});
}
this its not tested, but should be a good start:
_renderMenu: function( ul, items ) {
var self = this,
currentCategory = "";
$.each( items, function( index, item ) {
if ( item.parent.attr('label') != currentCategory ) {
ul.append( "- " + item.parent.attr('label') + "
" );
currentCategory = item.parent.attr('label');
}
self._renderItem( ul, item );
});
}
if this doesnt work, maybe you should debug to see whats into the items array that comes as a parameter of _renderMenu.
a side note: this is called MonkeyPatching, i wouldnt recommend doing this a lot, but since the docs show it, id say do it.