Write an simple example in http://jsfiddle.net/2RNFj/3/
You just need to provide the objects and supply it to Bloodhound
to set the source of typehead
:
var links = [{name: "abc", link: "http://www.example1.com"},
{name: "nbc", link: "http://www.example2.com"}];
var source = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
local: links
});
source.initialize();
$('#custom-templates .typeahead').typeahead(null, {
name: 'matched-links',
displayKey: 'name',
source: source.ttAdapter(),
templates: {
empty: [
'<div class="empty-message">',
'unable to find any Best Picture winners that match the current query',
'</div>'
].join('\n'),
suggestion: Handlebars.compile('<p><a href="{{link}}">{{name}}</a></p>')
}
});