【发布时间】:2014-06-20 10:40:16
【问题描述】:
我已经包含了 jQuery 2.1 bootstrap 3.x 和最新的 typeahead。这是我的代码:
<script type="text/javascript">
$(document).ready(function () {
var bestPictures = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
prefetch: {
url: 'TypeAheadPrefetch.ashx',
filter: function (list) {
return $.map(list, function (country) { alert(country); return { name: country }; });
}
},
remote: 'AutoComplete.asmx/GetSuperSearchTypeAhead?q=%QUERY'
});
bestPictures.initialize();
$("#tbSSearch").typeahead(null, {
name: 'best-pictures',
displayKey: 'value',
source: bestPictures.ttAdapter()
});
});
</script>
<input type="text" id="tbSSearch" placeholder="ST Super Search" class="form-control" />
prefetch.ashx 返回["a","b","c" 等。预取的字符串数组非常大,它应该包含正确的结果。所以不需要调用遥控器。但它确实!这是为什么?为什么没有可见的下拉菜单?
我的浏览器控制台在return s.split(/\s+/); 上第 134 列第 12 行的 typeahead 库中显示错误
ps alert(country); 有效
【问题讨论】:
-
你能举一个 GetSuperSearchTypeAhead 返回的例子吗?
-
一个字符串数组转json(类似于prefetch.ashx)
标签: jquery typeahead.js bootstrap-typeahead