【发布时间】:2016-01-03 22:12:08
【问题描述】:
我正在尝试使用库 typeahead.bundle.js(typeahead + bloodhound)。
这是我的代码:
var engine = new Bloodhound({
datumTokenizer: function(datum) {
return Bloodhound.tokenizers.whitespace(datum.name);
},
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: "https://api.mapbox.com/geocoding/v5/mapbox.places/%QUERY.json?country=fr&access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6IlhHVkZmaW8ifQ.hAMX5hSW-QnTeRCMAy9A8Q",
wildcard: "%QUERY",
rateLimitWait: 1000,
filter: function(response) {
return $.map(response.features, function(city) {
return {
name: city.place_name,
longitude: city.geometry.coordinates[0],
latitude: city.geometry.coordinates[1]
}
});
}
}
});
var promise = engine.initialize();
promise.done(function() {
$(".typeahead").typeahead({
minLength: 2,
highlight: true,
hint: false
},
{
displayKey: "name",
source: engine.ttAdapter()
});
});
一切正常,但没有显示结果。
有人可以帮我吗?
谢谢!
【问题讨论】:
-
无法满足请求。这是我尝试打开网址时得到的结果
-
您的远程 URL 无效
-
该网址正在运行...
标签: javascript autocomplete typeahead bloodhound