2014-10-29 98 views
0

我遇到的问题是当我开始键入时,建议显示,但只按字母顺序显示,不更新。就好像它不根据我的输入过滤结果。据我可以告诉我正确获取数据。 json响应来自The Echo Nest here。我后面的信息是来自json响应的流派名称。twitter typeahead.js没有更新建议

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/

回答

1

在这里我要回答我的问题。所以事实证明我使用了错误的查询。这本来是

http//developer.echonest.com/api/v4/genre/search?api_key=JSSXGZIEPOLRS21K7&format=json&results=10&name=%QUERY

其中,%QUERY是,我猜通过typeahead.js使用的文本输入字段这就是搜索对抗。 随着原始查询:

http://developer.echonest.com/api/v4/artist/list_genres?api_key= JSSXGZIEPOLRS21K7&format=json

没有在哪里添加%QUERY,因为它只是返回的清单,该清单是不可搜索上述查询。