【发布时间】:2014-04-17 19:00:28
【问题描述】:
我正在尝试使用 Bootstrap 3's Typeahead script 自动填充机场查询。
这是我尝试使用的网络服务: http://airportcode.riobard.com/about#about
我已经修改了另一个工作 jsfiddle(原来的工作源和数组键被注释掉并替换为新的)
// instantiate the bloodhound suggestion engine
var airports = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
//url: 'http://api.themoviedb.org/3/search/movie?query=%QUERY&api_key=470fd2ec8853e25d2f8d86f685d2270e',
url: 'http://airportcode.riobard.com/search?q=%QUERY&fmt=JSON',
filter: function (airports) {
return $.map(airports.results, function (airport) {
return {
//value: airport.title
value: airport.name
};
});
}
}
});
// initialize the bloodhound suggestion engine
airports.initialize();
// instantiate the typeahead UI
$('.typeahead').typeahead(null, {
name: 'airports',
displayKey: 'value',
source: airports.ttAdapter()
});
http://jsfiddle.net/UkB7u/109/
不知道为什么它不工作,据我所知它应该按原样工作,但它没有。
【问题讨论】:
标签: javascript jquery bootstrap-typeahead