当用户滚动到列表的末尾时,需要调用API,以使用Angular CDK虚拟滚动加载下一批数据

发布于 2025-01-24 12:29:06 字数 435 浏览 3 评论 0原文

我正在使用以下逻辑来确定用户是否在列表的末尾。但是,在以下情况下,end === total多次触发多个API调用。实际末端和总数应仅在用户处于列表末尾时仅一次。有人可以指出为什么这种奇怪的行为吗? scrollChange是在html (scrolledindexchange)中触发

scrollChange(e: any) {    
const end = this.viewport.getRenderedRange().end;
const total = this.viewport.getDataLength();        
if (end === total) {
  console.log('end reached');
  // Call my API to update my list     
}

I am using below logic to determine if User is at the end of the List. However in the Below case end === total multiple times which is triggering multiple API calls. In actual end and total should be equal only once when the user is at the end of the List. Can any one point out why such strange behaviour? ScrollChange is triggered in HTML (scrolledIndexChange)="scrollChange($event)"

scrollChange(e: any) {    
const end = this.viewport.getRenderedRange().end;
const total = this.viewport.getDataLength();        
if (end === total) {
  console.log('end reached');
  // Call my API to update my list     
}

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文