我是ionic framework.Currently的新手,我正在开发ionicsidemenu应用。
我有100多条记录,我想一次显示20条记录。当向下滚动时,获取下20条记录。为此,我使用ion-infinite-scroll,但我无法理解如何调用下20条记录。我正在使用webservice来获取记录。
请帮帮我。
发布于 2017-04-25 02:05:14
在这种情况下,您必须使用array而不是object,因为在array中推送项比推送到object中更容易。Ionic documentaton在他们的示例中也使用了数组。
查看:
<div ng-repeat="item in data">...</div>
<ion-infinite-scroll (ionInfinite)="getData()">
<ion-infinite-scroll-content></ion-infinite-scroll-content>
</ion-infinite-scroll>控制器:
$scope.data = [];
var page = 1;
$scope.getData = function(){
$http.get('http://example.com?page='+page).then(function(response){
page++;
$.each(response,function(key,item){
$scope.data.push(item);
});
}, function(error){
});
}当滚动到达ion时,无限滚动函数将被调用。刚开始的时候,屏幕上没有数据,所以在没有滚动的情况下,会自动调用ion-无限滚动函数来加载第一个页面。
发布于 2017-06-09 13:11:55
将limitTo与无限滚动一起使用。AngularJS ng-repeat 1.1.4版提供的limitTo选项。我稍微修改了无限滚动指令,使在没有100%窗口高度的容器中滚动成为可能。
ng-repeat="item in items | orderBy:prop | filter:query | limitTo:limit"请注意,limit是$scope中的一个变量,因此更改它会自动调整呈现项的数量。和递增限制,只渲染添加的元素。
<table>
<tr ng-repeat="d in data | limitTo:totalDisplayed"><td>{{d}}</td></tr>
</table>
<button class="btn" ng-click="loadMore()">Load more</button>
//the controller
$scope.totalDisplayed = 20;
$scope.loadMore = function () {
$scope.totalDisplayed += 20;
};
$scope.data = data;或尝试此解决方案
<body>
<pane ng-controller="MainCtrl">
<header-bar title="'Infinite Scroll Example'">
</header-bar>
<content has-header="true" padding="true" on-infinite-scroll="addMoreItem">
<div class=" list padding">
<div ng-repeat="item in items | limitTo:numberOfItemsToDisplay" class="item" type="item-text-wrap">
<h3>{{item}}</h3>
</div>
</div>
</content>
</pane>
</body>js代码
angular.module('myApp', ['ionic'])
.controller('MainCtrl', function($scope) {
$scope.numberOfItemsToDisplay = 20; // number of item to load each time
$scope.items = getData();
function getData() {
var a = [];
for (var i=1; i< 1000; i++) {
a.push(i);
}
return a;
}
$scope.addMoreItem = function(done) {
if ($scope.items.length > $scope.numberOfItemsToDisplay)
$scope.numberOfItemsToDisplay += 20; // load 20 more items
done(); // need to call this when finish loading more data
}
});在滚动时将显示20个项目。
https://stackoverflow.com/questions/43589628
复制相似问题