ng-repeat with limitTo 功能与起始索引

ng-repeat with limitTo feature with start index

假设我有 [1,2,3,4,5,6,7] 数组,我需要拆分成它以便我总是有 3 个对象,即 [1,2,3], [4,5,6] , [5,6,7] 单击页面中的下一步。如何使用 angularjs 的起始索引和 limitTo 功能来实现这一点?

检查您的 ng-click 处理程序中数组的长度将是我处理此问题的方法。

类似于以下内容:

$scope.items = [1, 2, 3, 4, 5, 6, 7];

$scope.startFrom = 0;

$scope.nextPage = function () {
    if ($scope.startFrom + 3 > $scope.items.length - 3) {
        $scope.startFrom = $scope.items.length - 3;
    }
    else {
        $scope.startFrom += 3;
    }
};

然后:

ng-repeat="item in items | limitTo: 3: startFrom"

如果您在使用 startFrom 时遇到任何问题,您可能需要检查 Angular 的版本。有关详细信息,请参阅