I use Bloodhound to retrieve data from the database, then twitter typeahead to display the options below the search box.
Currently, part of the snoop finds the required objects, but typeahead does not display them.
var artist_retriever = new Bloodhound({
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: "/artists?query=%QUERY",
wildcard: '%QUERY',
transform: function(array_of_artists){
array_of_artists = create_artist_descriptions(array_of_artists)
console.log(array_of_artists)
return array_of_artists
}
},
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('artist'),
});
searcher = $('.typeahead').typeahead(
{
hint: false
},
{
source: artist_retriever.ttAdapter(),
displayKey: 'artist',
templates: {
notFound: new_artist_option_template(),
footer: new_artist_option_template()
}
}
)
Update
Turns out there is a weird bug in typeahead. It seems to work only with the "limit" attribute set to a maximum of 4. If you set the "limit" to 5, typeahead does not give anything.
searcher = $('.typeahead').typeahead(
{
hint: false
},
{
source: artist_retriever.ttAdapter(),
displayKey: 'signature',
limit: 4,
templates: {
notFound: new_artist_option_template(),
footer: new_artist_option_template()
}
}
source
share