简体   繁体   English

如何提高自动完成性能?

[英]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. 我使用https://github.com/Pixabay/jQuery-autoComplete并将其应用于文本框进行搜索并且可以正常工作,问题是我获取了大量数据,浏览器冻结了几秒钟,然后才加载建议。 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: 您应该像这样使用lodash:

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 从此处获取有关防抖动的更多参考: https : //lodash.com/docs/4.17.10#debounce

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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