簡體   English   中英

無限滾動重復行

[英]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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM