简体   繁体   中英

How to improve autocomplete performance?

I used https://github.com/Pixabay/jQuery-autoComplete and applied it to a textbox for searching and it works, the problem is I'm getting a lot of data and the browser freezes for a few seconds before loading the suggestions. So I limited the result from the query and it improved the performance. But now, the problem is, autocomplete is not getting all possible suggestions even though the string is already very specific.

So what I did is I update the source for the autocomplete as I type, but what happens is, As I type, the textbox is being repeatedly initialized and I get multiple suggestion boxes from a single textbox.

Is there a way to change the source of the already initialized autocomplete?

You should use lodash Like this:

function autocomplete(a) {
   console.log(a);
}

var realFunction = _.debounce(autocomplete, 500);
// Now you can call like this 'realFunction()' on keyup

Get Reference more about Debounce from here: https://lodash.com/docs/4.17.10#debounce

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM