I want to use prefetch and I can't have it working ! Here is my code :
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() }; });
}
It doesn't work.
If I use remote instead of prefetch it works !
var bloodHound = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
limit: 10,
remote: pref
});
I can't anderstand.
Can anyone help me ?
clearPrefetchCache
. AddingclearPrefetchCache
beforeinitialize
helped. Though it doesn't explain, what's going on. – Shammer