我已经设置了typeahead.js版本0.11.1以从geobytes API中提取城市。这里,不只是一个codepen:来自typeahead.js的奇怪行为
http://codepen.io/jeremeevans/pen/OVPram
var cities = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace(),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: "http://gd.geobytes.com/AutoCompleteCity?callback=?&template=<geobytes%20city>,%20<geobytes%20code>&filter=US&q=%QUERY",
wildcard: "%QUERY",
dataType: "jsonp",
transform: function (response) {
return response;
}
},
limit: 10
});
$("#city").typeahead({
minLength: 3,
highlight: true,
hint: true
}, {
name: "US-Cities",
source: cities
});
的怪异行为,我看到的是,当我开始打字西雅图,当我到达“座位”这只是列出两个结果,“ Seaton,IL“和”Seatonville,IL“。我知道API会返回更多的结果,其中包括“华盛顿州西雅图”。此外,如果您开始搜索“Everett”,所有搜索结果将在“Everet”中删除,并且在您到达“Everett”之前保持隐形状态 - 此时会显示“Everett,MA”和“Everett,PA”,但不包含“Everett ,WA“。
与0.11.1版相关的选项和文档的文档在https://github.com/twitter/typeahead.js上相当糟糕 - 我真的很感谢有关如何使用它的一些见解,而不是它的屠夫,它会显示结果。
也许检查出:http://stackoverflow.com/questions/31007825/bootstrap-typeahead-not-showing-hints-as-expected – Reid