【发布时间】:2016-07-14 12:45:31
【问题描述】:
我正在做一个离子角度项目。有一个部分我正在实现无限滚动,当我滚动到底部时,我看到数据出现了。
我意识到数据以某种方式预先填充和隐藏,等待用户到达页面底部时出现。因为没有调用服务器来加载其他提要,所以我一次显示 5 条记录。
从 php 脚本,我已转换为 json。我有 60 行,从 chrome 控制台读取 json 长度为 60,这意味着所有 60 行都已加载,前提是数据已经预先填充。
有没有一种方法可以一次显示 5 条记录,然后当用户滚动到底部时,它会传递最后一个 id,因此会调用服务器以加载提要?
JS:
.controller('feedsctrl',['$scope','$http',function($scope,$http){
$http.get('http://usefulsite.com/app/feeds.php').success(function(data){
$scope.feeds= console.log(data); ;
$scope.feeds=data;
$scope.numberOfItemsToDisplay = 5; // Use it with limit to in ng-repeat
$scope.addMoreItem = function(done) {
if ($scope.feeds.length > $scope.numberOfItemsToDisplay)
$scope.numberOfItemsToDisplay += 5; // load number of more items
$scope.$broadcast('scroll.infiniteScrollComplete')
});
php
SELECT * FROM users order by fname asc
HTML
<ion-content overflow-scroll="false" has-bouncing="true">
<div ng-controller="feedsctrl" class="list card has-subheader" ng-repeat="item in feeds | filter:scheduleSearch | limitTo:numberOfItemsToDisplay">
<div class="item item-avatar">
<img src="http://usefulsite.com/resize_image/images.php?image={{item.profile_pix}}&new_width=100&new_height=100">
<h2><a class="names" href="#/tab/source/{{item.profile_id}}">{{item.fname}} {{item.lname}}</a></h2>
<p>November 05, 1955</p>
</div>
<div class="item item-body">
<img class="full-image" src="http://usefulsite.com/aoo/resize_image/images.php?image={{item.pic}}&new_width=800&new_height=800">
<p>{{item.fname}} {{item.lname}}</p>
</div>
</div>
<ion-infinite-scroll
on-infinite="addMoreItem()"
distance="1%"
ng-if="feeds.length > numberOfItemsToDisplay">
</ion-infinite-scroll>
【问题讨论】:
-
对我来说,您希望用户向下滚动页面,当他们到达最后一项时,第一项将显示出来,等等 ,,,, ect,,,?即 item1,item2,item3,item1,item2,item3?
标签: javascript php angularjs json ionic-framework