angular - Angular - 如何消除电话抖动?
问题描述
我有一个页面,用户可以在其中输入一个值到一个字段中,它执行搜索并将其返回给用户。
问题是,如果我输入得太快,它会进行多次调用,有时会跳过我输入的最后一个字符并使用它之前的调用。
我正在寻找一种方法来限制它并发现debounce
.
我觉得我没有正确使用它,因为它似乎对我正在做的事情没有影响。
// Component
sub: Subscription;
this.sub = this._empSearchService.employeeSearchData$
.debounceTime(1000)
.subscribe(
results => {
if (results) {
...
}
}
);
...
// On Key Up Event
this._empSearchService.searchMultipleEmployees(data)
.then((data: any) => {
this._empSearchService.updateSearchedEmployees(data);
});
// Service
private employeeSearchSub = new BehaviorSubject<any>(null);
employeeSearchData$ = this.employeeSearchSub.asObservable();
updateSearchedEmployees(obj) {
this.employeeSearchSub.next(obj);
};
对此有什么想法吗?
我担心的是,当我在 1 秒内输入 4 个字符时,我会看到 4 个网络调用。我想我应该只看到一个?
解决方案
推荐阅读
- android - 如何使用 Android Webview 加载单屏 Web 应用程序?
- python - 使用 Dash plotly 删除响应功能
- c# - Automapper - 如何实现查找
- xml - XSLT:在重新排列 XML 时面临多个父节点的问题
- r - R通过grep搜索将数据附加到df列(每个模式=新列)
- publishing - 如何使用 Adobe Animate 制作 Android App Bundle 以将其发布到谷歌商店?
- r - R:一张图中日期对象的两个折线图
- r - 如何从文件名中获取最新日期
- c# - RazorPages 如何将 GET 参数传递给 OnGet?
- node.js - 尝试在 backeng 中比较密码时出错 - NODE.JS