无限滚动,$http GET触发两次
infinite scrolling with $http GET firing twice
currentPage = 1;
$scope.loadPages = function () {
Array.prototype.pushArray = function () {
this.push.apply(this, this.concat.apply([], arguments));
};
if (currentPage < totalPages) {
$scope.infiniteScoll = true;
$http({
url: "http://someurl.php",
method: "GET",
params: {
"topicId": $stateParams.topicId,
"pageNumber": currentPage
}
}).then(function (response) {
$scope.posts.pushArray(response.data);
alert('w2');
currentPage = parseInt(response.data[0].currentPage) + 1;
totalPages = parseInt(response.data[0].totalPages) + 1;
}).
finally(function () {
$scope.infiniteScoll = false;
});
}
}
我会调试四个小时,仍然不知道为什么它会触发两次。 loadPages 是我的指令,如果我删除其中的所有内容并只留下 alert('f'),它只会触发一次。也许我在其他地方做错了什么?
尝试使用 infiniteScroll 布尔值阻止第二次调用,如以下代码所示
currentPage = 1;
$scope.loadPages = function () {
//should be declared out of this function
Array.prototype.pushArray = function () {
this.push.apply(this, this.concat.apply([], arguments));
};
if(!$scope.infiniteScoll && currentPage < totalPages) {
$scope.infiniteScoll = true;
$http({
url: "http://someurl.php",
method: "GET",
params: {
"topicId": $stateParams.topicId,
"pageNumber": currentPage
}
}).then(function (response) {
$scope.posts.pushArray(response.data);
alert('w2');
currentPage = parseInt(response.data[0].currentPage) + 1;
totalPages = parseInt(response.data[0].totalPages) + 1;
}).
finally(function () {
$scope.infiniteScoll = false;
});
}
};
在离子无限卷轴上给出immediate-check="false"
为我解决了这个问题。
喜欢这个
<ion-infinite-scroll
immediate-check="false"
on-infinite="loadMore()"
ng-if="hasMoreData"
distance="1%">
</ion-infinite-scroll>
相关文章:
- Meteor Router数据函数被调用两次
- 从MySQL数据库中获取输入数据需要两次页面刷新
- Module.start()已激发两次
- Jquery点击事件必须点击两次
- Append元素在运行两次函数后不显示
- 防止双击执行两次jQuery post请求
- 我必须点击两次才能激活任何按钮操作(离子/角度)
- JQuery定位:我可以滚动到正确的位置一次,但不能滚动两次
- 滚动时加载更多 滚动速度时一次工作两次
- 无限滚动,$http GET触发两次
- 平滑滚动并使用 Firefox 上的 popState 返回按钮 - 需要单击两次
- 猫头鹰旋转木马,一次滚动两个项目
- 自定义滚动条jScrollPane在iframe中出现两次
- 无限滚动加载内容两次
- 无限滚动执行动作两次或两次以上
- 我的无限滚动附加两次Safari和复制
- jQuery滚动事件触发两次
- 滚动事件导致自定义事件触发两次(应该是一次)
- Ajax无限滚动功能触发两次
- JQuery在加载react js组件数据时触发两次滚动