简体   繁体   English

实施自动建议功能的最佳方法?

[英]Best way to implement auto suggestions feature?

Currently, we are manually making a request call for suggestion data with every keyup, but cancelling the previous call made before making the new one. 当前,我们在每次键入按键时都手动请求建议数据,但是在进行新调用之前取消了先前的调用。 Is there a better way to do this with Angular.js/Node.js, or perhaps some other library that we can simply import? 有没有更好的方法可以使用Angular.js / Node.js或其他一些我们可以简单导入的库呢? Any suggestions would be appreciated. 任何建议,将不胜感激。

One thing that you can do is to send requests only after some small time of not typing, instead of on every keyup. 您可以做的一件事是仅在短时间内不输入请求后才发送请求,而不是在每次键入时都发送请求。

So for example when someone quickly types 20 characters then right now you're making 20 requests and cancel most of them. 因此,例如,当某人快速键入20个字符时,现在您要发出20个请求并取消其中的大多数请求。 But if you were sending a request only after for example half a second of non-typing then it would be just one request, with the same result. 但是,如果您仅在例如半秒不键入内容后才发送请求,那么它将只是一个请求,结果相同。

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

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