无限滚动重复行

Infinite scroll duplicates rows

我正在为我的 angularjs 项目使用 ngInfiniteScroll 依赖项。

每当我再次向上和向下滚动时,它都会复制行。

HTML

<table infinite-scroll="loadMore()" ng-controller="LastBookingsCtrl">

JavaScript

$scope.loadMore = function() {
$http.get("last.php?start=" + $scope.currentLoadIndex)
    .then(function (res) {
        if (res.data.length > 0) {
            var count = 0;
                for (var i = 0; i < res.data.length; i++) {
                    $scope.lastBookings.push(res.data[i]);
                    count++;
                }
            $scope.currentLoadIndex += count;
        }
    });
};

PHP

$start = $_GET['start'];
$query = "SELECT * FROM `performs` ORDER BY id DESC LIMIT ".$start.", 20";

我相信您每次都会得到相同的结果,因为您 $scope.currentLoadIndex 没有从 then() 正确更新。尝试将下一个索引设置为当前列表的长度,即:

$http.get("last.php?start=" + $scope.lastBookings.length)