擴大格蘭迪的使用點.slice()
。
我使用ngInfiniteScroll
當我需要延遲渲染/延遲加載數據。
我會保留那些3000條記錄出你的範圍,以防止不必要的拖累你的消化性能,然後將它們添加到您的示波器數據,你需要他們。這是一個例子。
var $app = angular.module('app', ['infinite-scroll']);
$app.controller('listingController', function($scope, $window) {
/*
* Outside of this controller you should bootstrap your data to a non-digested array.
* If you're loading the data via Ajax, save your data similarly.
* For example:
* <script>
* window._bootstrappedData = [{id:1,name:'foo'},{id:2,name:'bar'},...];
* </script>
*/
var currentPage, pageLength;
$scope.listOfItems = [];
currentPage = 0;
pageLength = 100;
$scope.nextPage = function() {
// make sure we don't keep trying to slice data that doesn't exist.
if (currentPage * pageLength >= $window._bootstrappedData.length) {
return false;
}
// append the next data set to your array
$scope.listOfItems.push($window._bootstrappedData.slice(currentPage * pageLength, (currentPage + 1) * pageLength));
currentPage++;
};
/*
* Kickstart this data with our first page.
*/
return $scope.nextPage();
});
而且你的模板:
<div ng-controller="listingController" infinite-scroll="nextPage()" infinite-scroll-distance="3">
<ul>
<li ng-repeat="item in listOfItems">{{item.name}}</li>
</ul>
</div>
你可以簡單的切片數組爲ng-repeat,你需要計數 – Grundy
@Grundy什麼是我需要的?如果我只是「重複」N個元素而不是所有元素,我將如何擁有一個滾動條?我的意思是......我不確定你確切地明白我在問什麼。你能重讀我的問題嗎? – alexandernst
例如:你有3000個項目的集合,首先你做的事情是:'arrForShow = items.slice(0,20)',然後在滾動上添加項目到'arrForShow'併爲此做'ng-repeat' – Grundy