I am writing a search functionality using typeahead.js. I am trying to figure out how debounce can be implemented for the search feature. I went through the typeahead docs, but I couldn't find any relevant information. How to implement the debounce in typeahead? The code is shown below.
$('input.typeahead').typeahead({
name: 'movies',
remote: 'http://localhost:3000/searchMovie?key=%QUERY',
limit: 10
});
If you are using bloodhound with twitter's typeahead.js library, there is a native option for debouncing the input for the remote lookup. bloodhound remote twitter typeahead doc on github
var my_bloodhound = new Bloodhound({
name : 'search_filter_' + my_filter,
datumTokenizer : Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer : Bloodhound.tokenizers.whitespace,
limit : 20,
prefetch : {
url : '/my_search.php?filter=' + my_filter,
filter : myFilterSearchTypeaheadResponse
},
remote : {
wildcard : 'LOOKUP',
url : '/my_search.php?filter=' + my_filter + '&query=LOOKUP',
rateLimitBy : 'debounce',
rateLimitWait : 600,
filter : myFilterSearchTypeaheadResponse
}
});
my_bloodhound.clearPrefetchCache();
my_bloodhound.clearRemoteCache();
my_bloodhound.initialize();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.