我想使用预取,但我不能让它工作!
这是我的代码:
function initAutocompletion() {
$("input[data-autocomplete-prefetch-url]").each(function () {
var $this = $(this);
var urlPrefetch = $this.data("autocomplete-prefetch-url");
var prefetch;
pref = {
url: urlPrefetch,
filter: filter
};
var bloodHound = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
limit: 10,
prefetch: pref
});
bloodHound.initialize();
$this
.typeahead('destroy')
.typeahead({
hint: true,
highlight: true,
minLength: 1
},
{
displayKey: 'value',
source: bloodHound.ttAdapter()
});
});
}
function filter(list) {
return $.map(list, function (v) { return { value: v.toString() }; });
}
它不起作用。
如果我使用远程而不是预取它可以工作!
var bloodHound = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
limit: 10,
remote: pref
});
我无法理解。
谁能帮我 ?
最佳答案
令人惊讶的是,今天早上它起作用了!
所以它驱使我认为它是关于缓存......它是!
在初始化 Bloodhound 之前添加 clearPrefetchCache() 可以解决问题。
bloodHound.clearPrefetchCache();
bloodHound.initialize();
我认为它没有显示任何建议,因为它缓存了一个空列表。
关于提前打字,猎犬 : remote works but not prefetch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23569375/