【问题标题】:ionic infinite scroll doesn't concat the resutls离子无限滚动不会连接结果
【发布时间】:2020-09-13 14:20:37
【问题描述】:

每次到达底部时,我都使用离子无限滚动来获取更多帖子
它工作正常,但它取代了不连接它的结果
这是代码
page=0

  getAllposts() {

    const url = `${this.API_URL}/getallposts?page=${this.page}`;

    return this.http.get<any[]>(url);
  }

getAllList() {
  this.getAllposts().subscribe(data => {
    this.showPosts = this.showPosts.concat(data) as PostModel[];

  
  });
} 



loadData(event) {

setTimeout(() => {
this.getAllList()
    event.target.complete();
  }, 2000);

this.page++
}
 

【问题讨论】:

    标签: angular typescript ionic-framework


    【解决方案1】:

    请尝试使用for loop 而不是cancat

    for (let i = 0; i < data.length; i++) {
              this.showPosts.push(data[i]);
    }
    

    【讨论】:

    【解决方案2】:

    你可以在这里使用spread operator..

    this.showPosts = [...this.showposts,...data];
    

    Reference

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-11
      • 2016-03-08
      • 1970-01-01
      • 2018-04-07
      • 2023-04-05
      • 2016-04-08
      相关资源
      最近更新 更多