在移动端已经不需要点击页码换页了,而是通过手触滑动,滑动到底部自动加载,这个demo是项目中写的一个例子,之总结了js部分,贴出代码分享,此功能依赖于infinite-
-
(function() {
-
-
var myApp = angular.module('myApp', ['infinite-scroll']);
-
-
myApp.controller('DemoController', function($scope, Reddit) {
-
$scope.reddit = new Reddit();
-
console.log("hello");
-
});
-
-
// Reddit constructor function to encapsulate HTTP and pagination logic
-
myApp.factory('Reddit', function($http) {
-
var Reddit = function() {
-
this.items = [];
-
this.busy = false;
-
this.page = 1;
-
};
-
-
Reddit.prototype.nextPage = function() {
-
if (this.busy) return;
-
this.busy = true;
-
-
var url = "" + this.page ;
-
$http.get(url).success(function(data) {
-
var items = data.items;
-
for (var i = 0; i < items.length; i++) {
-
this.items.push(items[i]);
-
}
-
this.page = data.page + 1 ;//第几页
-
this.busy = false;
-
}.bind(this));
-
-
};
-
-
return Reddit;
-
});
-
})()
json代码
-
{
-
"success":true,
-
"page":1,
-
"items":[
-
{
-
"id":1,
-
"author":"张三",
-
"title":"hello world 1",
-
"url":"",
-
"content":"abcd efg hijk lmn opq rst uvw xyz.....1"
-
},
-
{
-
"id":2,
-
"author":"李四",
-
"title":"hello world 2",
-
"url":"",
-
"content":"abcd efg hijk lmn opq rst uvw xyz.....2"
-
},
-
{
-
"id":1,
-
"author":"王五",
-
"title":"hello world 3",
-
"url":"",
-
"content":"abcd efg hijk lmn opq rst uvw xyz.....3"
-
},
-
{
-
"id":1,
-
"author":"张三1",
-
"title":"hello world 1",
-
"url":"",
-
"content":"abcd efg hijk lmn opq rst uvw xyz.....1"
-
},
-
{
-
"id":2,
-
"author":"李四1",
-
"title":"hello world 2",
-
"url":"",
-
"content":"abcd efg hijk lmn opq rst uvw xyz.....2"
-
},
-
{
-
"id":1,
-
"author":"王五1",
-
"title":"hello world 3",
-
"url":"",
-
"content":"abcd efg hijk lmn opq rst uvw xyz.....3"
-
},
-
{
-
"id":1,
-
"author":"张三2",
-
"title":"hello world 1",
-
"url":"",
-
"content":"abcd efg hijk lmn opq rst uvw xyz.....1"
-
},
-
{
-
"id":2,
-
"author":"李四2",
-
"title":"hello world 2",
-
"url":"",
-
"content":"abcd efg hijk lmn opq rst uvw xyz.....2"
-
},
-
{
-
"id":1,
-
"author":"王五2",
-
"title":"hello world 3",
-
"url":"",
-
"content":"abcd efg hijk lmn opq rst uvw xyz.....3"
-
}
-
]
-
}
阅读(1153) | 评论(0) | 转发(0) |