【发布时间】:2016-03-29 20:57:51
【问题描述】:
Typeahead 不显示建议。这是一个非常简单的城市查询。数据库返回正常。控制台正在记录我的输入。就是无法显示返回数据。
remote data
{"recID":"3699","Name":"Dupage","City":"West Chicago","Country":"United States"}
html
<input class="typeahead" type="text" placeholder="Enter City" size="32">
script
<script type="text/javascript">
var cities = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('City'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
prefetch: 'getAirports.php',
remote: {
url: 'getAirports.php?query=%QUERY',
wildcard: '%QUERY'
}
});
$('.typeahead').typeahead({
hint: true,
highlight: true,
minLength: 1
}, {
name: 'City',
display: 'City',
source: cities,
templates: {
suggestion: function (data) {
return data.City;
}
}
});
</script>
【问题讨论】:
-
如果删除预取会发生什么?
-
同样的结果。我也将 ?query= ("getAirports.php?query=") 添加到预取的末尾。仍然没有数据返回。可能是因为数组是键值。一直在到处寻找解决方案。
标签: jquery typeahead bloodhound