如何在页面加载时调用相同的请求,例如说5次,并通过无限滚动再次调用同一请求5次?每次currentCount应该增加1。
此外,infiniteScroll仅调用请求1次。如果我再次使用它,则没有通话请求。
我该如何实现?
这是我的.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);
})
}
答案 0 :(得分:1)
尝试下面的示例代码。希望它能工作并节省您的一天
<ion-content (ionScrollEnd)="logScrolling($event)">
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;
}