リモート API で Bloodhound を使用しており、リモート API から返された結果を変換する必要があります。
API URL はhttps://www.googleapis.com/books/v1/volumes?q=quiltingitems
で、リストであるプロパティを持つオブジェクトを返します。トップレベルのオブジェクトではなく、そのリストを Typeahead に返す必要があります。
ブラッドハウンドのドキュメントによると、これを行うはずの機能があるとのことですが、transform
機能させることができません。
これが私のコードです:
var books = new Bloodhound({
datumTokenizer: function(d) { return Bloodhound.tokenizers.whitespace(d.num); },
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: 'https://www.googleapis.com/books/v1/volumes?q=quilting'
},
transform: function(response) {
console.log('transform', response);
return response.items;
}
});
books.initialize();
// instantiate the typeahead UI
$('#myTextBox').typeahead(null, {
displayKey: function(suggestion) {
console.log('suggestion', suggestion);
return suggestion.volumeInfo.title + suggestion.volumeInfo.publishedDate;
},
source: numbers.ttAdapter()
});
ここにJSFIddleがあります:http://jsfiddle.net/2Cres/46/
リストを先行入力UIにフィードする必要があるため、items
これは機能しませんが、これは起こっていないようです。