【发布时间】:2015-02-05 20:59:45
【问题描述】:
我在我的网络应用程序中使用 typeahead.js 0.10.5。由于某些奇怪的原因,通过远程工作实时获取建议,而预取被破坏。这里发生了一些不明显和奇怪的事情。根据开发控制台和 Chrome 的网络监视器,它甚至没有对页面加载进行查询。当然,它会在我开始输入时进行查询。
这真的让我很难过——我在这里做错了什么?
// Instantiate the Bloodhound suggestion engine
var tags = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: '/tags/tags/search.json?q=%QUERY',
filter: function (taglist) {
// Map the remote source JSON array to a JavaScript object array
return $.map(taglist, function (tag) {
console.log(tag);
return {
value: tag.tag
};
});
}
},
prefetch: {
url: '/tags/tags/search.json?q=',
filter: function (taglist) {
// Map the remote source JSON array to a JavaScript object array
return $.map(taglist, function (tag) {
console.log(tag);
return {
value: tag.tag
};
});
},
}
});
// Initialize the Bloodhound suggestion engine
tags.initialize();
// Instantiate the Typeahead UI
$('#search-tags').typeahead(null, {
displayKey: 'value',
source: tags.ttAdapter(),
hint: true,
highlight: true
});
【问题讨论】:
-
尝试从浏览器的 localStorage 中删除条目并重新开始。
-
嗯,我尝试使用 Chrome 的“删除最近的活动”并没有这样做,但是在从本地存储中手动删除密钥后它起作用了。将此作为答案发布,我会将其标记为正确。
标签: javascript jquery typeahead.js twitter-typeahead