Reputation: 21
The problem I'm having is when I begin to type, the suggestions show but only in alphabetical order and don't update. Its as if its not filtering the results based on my input. As far as I can tell Im getting the data correctly. The json response is from The Echo Nest here. The information I'm after is the genres name from the json response which I'm getting.
var search = new Bloodhound({
datumTokenizer: function(data) { return Bloodhound.tokenizers.whitespace(data.name); },
queryTokenizer: Bloodhound.tokenizers.whitespace,
limit: 3,
remote: {
url:'http://developer.echonest.com/api/v4/artist/list_genres?api_key= JSSXGZIEPOLRS21K7&format=json',
filter: function(search) {
return $.map(search.response.genres, function(data) { return { name: data.name }; });
}
}
});
search.initialize();
$('.typeahead').typeahead(null, {
name: 'genres',
displayKey: 'name',
source: search.ttAdapter()
});
http://jsfiddle.net/o9pcso1u/1/
Upvotes: 0
Views: 293
Reputation: 21
I'll answer my own question here. So it turned out I was using the wrong query. It should have been
http//developer.echonest.com/api/v4/genre/search?api_key=JSSXGZIEPOLRS21K7&format=json&results=10&name=%QUERY
where %QUERY is, what I'm guessing the text input field thats used by typeahead.js to search against. With the original query of:
http://developer.echonest.com/api/v4/artist/list_genres?api_key= JSSXGZIEPOLRS21K7&format=json
there was no where to add the %QUERY as it just returned a list and that list wasn't searchable with the above query.
Upvotes: 1