如何使用页面增量多次进行相同的http调用

问题描述 投票:0回答:1

如何在页面加载时调用相同的请求5次并且使用无限滚动它再次调用相同的请求5次?每次当前Count应该增加1。

infiniteScroll也只调用一次请求。如果我再次使用它,则不会有呼叫请求。

我怎样才能实现这一目标?

这是我的.ts文件

currentCount = 0

getUserList() {
    this.showLoader();
    this.search.page = this.currentCount;
    this.authService.getData(this.search, "search")
      .then((result) => {
        let yourString = typeof result == 'object' && result["_body"] ? result["_body"] : [];
        let res = yourString.substring(1, yourString.length - 1);
        this.response = JSON.parse(res);
        this.userData = JSON.parse(res).details.data
      }, (err) => {
        console.log(err);
      });
  }

  doInfinite(): Promise<any> {
    this.currentCount = this.currentCount + 1;
     return new Promise((resolve) => {
      setTimeout(() => {
        this.authService.getData(this.search, "search")
          .then((result) => {
            let yourString = typeof result == 'object' && result["_body"] ? result["_body"] : [];
            let res = yourString.substring(1, yourString.length - 1);
            this.response = JSON.parse(res);
              const newData = this.response.details.data
              console.log(newData);
              for (let i = 0; i < newData.length; i++) {
                this.userData.push(newData[i]);
              }
          }, (err) => {
            console.log(err);
          });

        console.log('Async operation has ended');
        resolve();
      }, 500);
    })
  }
ionic-framework ionic3
1个回答
1
投票

请尝试以下示例代码。希望它能运作并节省您的一天

Html文件

<ion-content (ionScrollEnd)="logScrolling($event)">

Ts文件

logScrolling(event)
{
 this.book_details();
}
book_details()
{
sendData= {'name':'Test'}
this.myservice.online_service(this.funcName, sendData).subscribe(response => {
    if ( response.status === 'success' && response.data.length > 0) {
      this.bookDetails = this.bookDetails.concat(response.data);
      ++this.current_page;
}
© www.soinside.com 2019 - 2024. All rights reserved.