Skip to content

Instantly share code, notes, and snippets.

@bshyong
Created August 29, 2012 19:44
Show Gist options
  • Save bshyong/3517822 to your computer and use it in GitHub Desktop.
Save bshyong/3517822 to your computer and use it in GitHub Desktop.
Jquery UI autocomplete example
$.ui.autocomplete, {
_renderMenu: function( ul, items ) {
// use this to manipulate the entire array of results
// if you overwrite this method, make sure to call _renderItem for each item
// or else the individual items will not render, only the menu will render
// example below.
var self = this;
$.each(items, function(index, item){
self._renderItem(ul, item);
}
},
_renderItem: function(ul, item){
// use this to specify how your autocomplete results are rendered
// example below. note you need to use the data method
// otherwise the object's attributes will not be sent with the object when it is rendered.
return $( "<li></li>" )
.data( "item.autocomplete", item )
.append( "<a>" + item.label + "</a>" )
.appendTo( ul );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment