ionic 上拉加载更多&瀑布流加载&滚动到底部加载更多 主意事项
首先下拉刷新的代码是这样的,标红的地方为关键代码
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title>菜鸟教程(runoob.com)</title>
<link href="http://www.runoob.com/static/ionic/css/ionic.min.css" rel="stylesheet">
<script src="http://www.runoob.com/static/ionic/js/ionic.bundle.min.js"></script>
<script type="text/javascript">
angular.module('starter', ['ionic']) .run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
}) .controller( 'actionsheetCtl',['$scope','$timeout' ,'$http',function($scope,$timeout,$http){ $scope.items=[
{
"name":"HTML5"
},
{
"name":"JavaScript"
},
{
"name":"Css3"
}
]; $scope.doRefresh = function() {
$http.get('http://www.runoob.com/try/demo_source/item.json') //注意改为自己本站的地址,不然会有跨域问题
.success(function(newItems) {
$scope.items = newItems;
})
.finally(function() {
$scope.$broadcast('scroll.refreshComplete');
});
};
}])
</script>
</head>
<body ng-app="starter" ng-controller="actionsheetCtl" > <ion-pane>
<ion-content >
<ion-refresher pulling-text="下拉刷新" on-refresh="doRefresh()"></ion-refresher>
<ion-list>
<ion-item ng-repeat="item in items" ng-bind="item.name"></ion-item>
</ion-list>
</ion-content>
</ion-pane>
</body>
</html>
默认打开页面是这样的
/****************页面载入方法************************/
$http.get(findUrl+'?class=goods&name='+name+'&page=1') //注意改为自己本站的地址,不然会有跨域问题
.success(function(newItems) {
$scope.items = newItems.content;
})
.finally(function() {
$scope.$broadcast('scroll.refreshComplete');
});
<ion-list>
<div class="content ionic-pseudo card" ng-repeat="item in items" >
上拉加载更多可以模仿下拉刷新写
首先在</ion-list>下及</ion-content>上(不一定非得是</ion-list>,这里是放在列表最下方的意思)上放置代码
。。。。。
</ion-list>
<ion-infinite-scroll ng-if="!noMorePage" immediate-check="false" on-infinite="loadMore()" distance="1%" ></ion-infinite-scroll>
</ion-content>
</body>
</html>
immediate-check="false"是实验了很多次后来加上的,具体见:http://feifei.im/archives/276
然后是js代码部分
$scope.currentPage=1;//定义下拉加载分页的初始值
$scope.loadMore=function(){
var start = $scope.start;
var goods = $scope.goods;
var now_city = $scope.now_city;
$scope.currentPage += 1;//每当滚动到底部,页码累计加1
$http.get(findUrl+'?class=goods&start='+start+'&goods='+goods+'&now_city='+now_city+'&page='+$scope.currentPage) //注意改为自己本站的地址,不然会有跨域问题
.success(function(newItems) {
for (var i=0;i<newItems.content.length;i++){//newItems.content.length,当前json的数量
$scope.items.push(newItems.content[i]);//一个一个取出来,推送到原来的items里
}
if (newItems.content.length < 10) {//当json的数量小于10(已经确定了一页为10条数据),说明页面到底了
$scope.noMorePage=true;//禁止滚动触发时间
}
$scope.$broadcast('scroll.infiniteScrollComplete');
})
};
$scope.currentPage这个值会一直跑,一直累计加1,当你刷新页面后,这就会是个bug,所以,在下拉刷新代码里添加了
$scope.currentPage=1;
$scope.noMorePage=false;
还原代码
<html >
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title>app</title>
<link href="css/ionic.min.css" rel="stylesheet">
<script src="js/ionic.bundle.min.js"></script>
<script src="js/config.js"></script> <script type="text/javascript"> var app = angular.module( 'starter', ['ionic'] ).config( [
'$compileProvider',
function( $compileProvider )
{
$compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|tel|file|sms):/);
// Angular before v1.2 uses $compileProvider.urlSanitizationWhitelist(...)
}]) .controller( 'actionsheetCtl',['$scope','$location','$timeout' ,'$http',function($scope,$location,$timeout,$http){ //$scope.PageIndex = 1;
$scope.currentPage=1;
//$scope.noMorePage=false; $scope.domain = url;
var name = $location.search().name; /****************页面载入方法************************/
$http.get(findUrl+'?class=goods&name='+name+'&page=1') //注意改为自己本站的地址,不然会有跨域问题
.success(function(newItems) {
$scope.items = newItems.content;
})
.finally(function() {
$scope.$broadcast('scroll.refreshComplete');
}); /****************刷新方法************************/
$scope.doRefresh = function() {
//alert($scope.currentPage);
$scope.currentPage=1;
$scope.noMorePage=false; //console.log($scope.PageIndex);
var start = $scope.start;
var goods = $scope.goods;
var now_city = $scope.now_city;
$http.get(findUrl+'?class=goods&start='+start+'&goods='+goods+'&now_city='+now_city+'&name='+name+'&page=1') //注意改为自己本站的地址,不然会有跨域问题
.success(function(newItems) {
$scope.items = newItems.content;
})
.finally(function() {
$scope.$broadcast('scroll.refreshComplete'); });
}; /*
function a(){
var i = 2;
function b(){
//alert(i++);
var page = i++;
return page;
}
return b;
}
var c = a();
*/ /****************加载方法************************/ $scope.loadMore=function(){
var start = $scope.start;
var goods = $scope.goods;
var now_city = $scope.now_city;
//var p = c(); //$scope.PageIndex++;
$scope.currentPage += 1;
//console.log($scope.currentPage); $http.get(findUrl+'?class=goods&start='+start+'&goods='+goods+'&now_city='+now_city+'&page='+$scope.currentPage) //注意改为自己本站的地址,不然会有跨域问题
.success(function(newItems) {
//$scope.items.push(newItems.content);
//console.log($scope.items);
//var objs =[{a:1},{a:2}];
//angular.forEach(newItems.content, function(data,index,array){
//data等价于array[index]
console.log(newItems.content.length); for (var i=0;i<newItems.content.length;i++)
{
$scope.items.push(newItems.content[i]);
} if (newItems.content.length < 10) {
$scope.noMorePage=true;
} //}); $scope.$broadcast('scroll.infiniteScrollComplete'); }) //$scope.havaMore=false;
}; }]) </script> <style>
body,input,h2{
font-family:Microsoft YaHei;
}
.icon{
color: #808080;
list-style-type: none; font-size: 2em;
}
.price{
border-radius: 5px;
background: red;
color: white;
font-size: 0.9em;
padding-top:0.2em;
}
a{
text-decoration:none;
color:black;
}
</style> </head> <body ng-app="starter" > <ion-content ng-controller="actionsheetCtl" >
<ion-refresher pulling-text="下拉刷新" on-refresh="doRefresh()"></ion-refresher> <div class="row"> <div class="col col-25">
<div class="col-demo"> <div class="item item-input ">
<input type="text" placeholder="地址" ng-model="start">
</div> </div>
</div> <!-- <div class="col col-10">
<center><li class="ion-arrow-swap icon" style="margin-top: 40%;" ></li></center>
</div>--> <div class="col col-25">
<div class="col-demo"> <div class="item item-input ">
<input type="text" placeholder="产品" ng-model="goods" >
</div> </div>
</div> <div class="col col-30"> <label class="item item-input item-select"> <div class="input-label">
种类
</div> <select ng-model="now_city">
<option value ="">全部</option>
<option value ="蔬菜">蔬菜</option>
<option value ="果品">果品</option>
<option value="粮油">粮油</option>
<option value="水产品">水产品</option>
<option value="畜产品">畜产品</option>
</select> </label> </div> <button class="ion-search icon button button-icon" ng-click="doRefresh()"></button> </div> <ion-list> <div class="content ionic-pseudo card" ng-repeat="item in items" > <div class="list list-inset"> <div class="item item-thumbnail-left">
<img src="{{domain}}/upload/{{item.pic}}.png"> <div class="row">
<div class="col"> <h2>{{item.goods}}</h2></div>
<div class="col"> <div class="price"><center>¥{{item.price}}</center></div> </div>
</div> <h2 >发布日期:{{item.date}}</h2>
<h2 >供货地址:{{item.start}}</h2> </div> <div class="item">
<div class="row">
<div class="col"> <center style="color:#F0AB4B">发布人:{{item.name}}</center></div>
<div class="col"> <center style="color:#97D152">种类:{{item.now_city}}</center></div>
</div>
</div> <div class="item">
<div class="row" >
<div class="col" style="border-right:1px solid #F0EFF1"> <center>
<h2 style="color:#0779FF;
font-weight:bold;"><a href="tel:{{item.phone1}}">给TA打电话</a></h2>
</center> </div>
<div class="col">
<center>
<h2 style="color:#0779FF;
font-weight:bold;"><a ng-href="sms:{{item.phone1}}">给TA发短信</a></h2>
</center> </div>
</div>
</div> </div> </div> </ion-list> <ion-infinite-scroll ng-if="!noMorePage" immediate-check="false" on-infinite="loadMore()" distance="1%" ></ion-infinite-scroll> </ion-content> </body>
</html>
改版2(修复查询bug)
<html >
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title>app</title>
<link href="css/ionic.min.css" rel="stylesheet">
<script src="js/ionic.bundle.min.js"></script>
<script src="js/config.js"></script> <script type="text/javascript"> var app = angular.module( 'starter', ['ionic'] ).config( [
'$compileProvider',
function( $compileProvider )
{
$compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|tel|file|sms):/);
// Angular before v1.2 uses $compileProvider.urlSanitizationWhitelist(...)
}]) .controller( 'actionsheetCtl',['$scope','$location','$timeout' ,'$http',function($scope,$location,$timeout,$http){ //$scope.PageIndex = 1;
$scope.currentPage=1;
//$scope.noMorePage=false; $scope.domain = url;
var name = $location.search().name; /****************页面载入方法************************/
$http.get(findUrl+'?class=goods&name='+name+'&page=1') //注意改为自己本站的地址,不然会有跨域问题
.success(function(newItems) {
$scope.items = newItems.content;
}) /****************刷新方法************************/
$scope.doRefresh = function() {
//alert($scope.currentPage);
$scope.currentPage=1;
$scope.noMorePage=false; //console.log($scope.PageIndex);
var start = $scope.start;
var goods = $scope.goods;
var now_city = $scope.now_city; $http.get(findUrl+'?class=goods&start='+start+'&goods='+goods+'&now_city='+now_city+'&name='+name+'&page=1') //注意改为自己本站的地址,不然会有跨域问题
.success(function(newItems) {
$scope.items = newItems.content;
}) $scope.$broadcast('scroll.refreshComplete'); }; /*
function a(){
var i = 2;
function b(){
//alert(i++);
var page = i++;
return page;
}
return b;
}
var c = a();
*/ /*************查询方法*************/
$scope.doSearch = function() {
var start = $scope.start;
var goods = $scope.goods;
var now_city = $scope.now_city; $scope.currentPage=1;
$scope.noMorePage=false; //alert(start);
$http.get(findUrl+'?class=goods&start='+start+'&goods='+goods+'&now_city='+now_city+'&name='+name+'&page=1')
.success(function(newItems) {
console.log(newItems.content);
//newItems.content;
$scope.items = newItems.content; })
//$scope.$broadcast('scroll.infiniteScrollComplete');
}; /****************加载方法************************/ $scope.loadMore=function(){
var start = $scope.start;
var goods = $scope.goods;
var now_city = $scope.now_city;
//var p = c(); //$scope.PageIndex++;
$scope.currentPage += 1;
//console.log($scope.currentPage); $http.get(findUrl+'?class=goods&start='+start+'&goods='+goods+'&now_city='+now_city+'&name='+name+'&page='+$scope.currentPage) //注意改为自己本站的地址,不然会有跨域问题
.success(function(newItems) {
//$scope.items.push(newItems.content);
//console.log($scope.items);
//var objs =[{a:1},{a:2}];
//angular.forEach(newItems.content, function(data,index,array){
//data等价于array[index]
//console.log(newItems.content); if ( newItems.content == null){
$scope.noMorePage=true;
} var length = newItems.content.length; for (var i=0;i<length;i++)
{
$scope.items.push(newItems.content[i]);
} if (newItems.content.length < 10) {
$scope.noMorePage=true;
} //}); $scope.$broadcast('scroll.infiniteScrollComplete'); }) //$scope.havaMore=false;
}; }]) </script> <style>
body,input,h2{
font-family:Microsoft YaHei;
}
.icon{
color: #808080;
list-style-type: none; font-size: 2em;
}
.price{
border-radius: 5px;
background: red;
color: white;
font-size: 0.9em;
padding-top:0.2em;
}
a{
text-decoration:none;
color:black;
}
</style> </head> <body ng-app="starter" > <ion-content ng-controller="actionsheetCtl" >
<ion-refresher pulling-text="下拉刷新" on-refresh="doRefresh()"></ion-refresher> <div class="row"> <div class="col col-25">
<div class="col-demo"> <div class="item item-input ">
<input type="text" placeholder="地址" ng-model="start">
</div> </div>
</div> <!-- <div class="col col-10">
<center><li class="ion-arrow-swap icon" style="margin-top: 40%;" ></li></center>
</div>--> <div class="col col-25">
<div class="col-demo"> <div class="item item-input ">
<input type="text" placeholder="产品" ng-model="goods" >
</div> </div>
</div> <div class="col col-30"> <label class="item item-input item-select"> <div class="input-label">
种类
</div> <select ng-model="now_city">
<option value ="">全部</option>
<option value ="蔬菜">蔬菜</option>
<option value ="果品">果品</option>
<option value="粮油">粮油</option>
<option value="水产品">水产品</option>
<option value="畜产品">畜产品</option>
</select> </label> </div> <button class="ion-search icon button button-icon" ng-click="doSearch()"></button> </div> <ion-list> <div class="content ionic-pseudo card" ng-repeat="item in items" > <div class="list list-inset"> <div class="item item-thumbnail-left">
<img src="{{domain}}/upload/{{item.pic}}.png"> <div class="row">
<div class="col"> <h2>{{item.goods}}</h2></div>
<div class="col"> <div class="price"><center>¥{{item.price}}</center></div> </div>
</div> <h2 >发布日期:{{item.date}}</h2>
<h2 >供货地址:{{item.start}}</h2> </div> <div class="item">
<div class="row">
<div class="col"> <center style="color:#F0AB4B">发布人:{{item.name}}</center></div>
<div class="col"> <center style="color:#97D152">种类:{{item.now_city}}</center></div>
</div>
</div> <div class="item">
<div class="row" >
<div class="col" style="border-right:1px solid #F0EFF1"> <center>
<h2 style="color:#0779FF;
font-weight:bold;"><a href="tel:{{item.phone1}}">给TA打电话</a></h2>
</center> </div>
<div class="col">
<center>
<h2 style="color:#0779FF;
font-weight:bold;"><a ng-href="sms:{{item.phone1}}">给TA发短信</a></h2>
</center> </div>
</div>
</div> </div> </div> </ion-list> <ion-infinite-scroll ng-if="!noMorePage" immediate-check="false" on-infinite="loadMore()" distance="1%" ></ion-infinite-scroll> </ion-content> </body>
</html>
ionic 上拉加载更多&瀑布流加载&滚动到底部加载更多 主意事项的更多相关文章
- XRecyclerView:实现下拉刷新、滚动到底部加载更多以及添加header功能的RecyclerView
介绍: 一个实现了下拉刷新,滚动到底部加载更多以及添加header功能的的RecyclerView.使用方式和RecyclerView完全一致,不需要额外的layout,不需要写特殊的adater. ...
- 滚动到底部加载更多及下拉刷新listview的使用
最新内容建议直接访问原文:滚动到底部加载更多及下拉刷新listview的使用 本文主要介绍可同时实现下拉刷新及滑动到底部加载更多的ListView的使用. 该ListView优点包括:a. 可自定义下 ...
- ionic-Javascript:ionic 上拉菜单(ActionSheet)
ylbtech-ionic-Javascript:ionic 上拉菜单(ActionSheet) 1.返回顶部 1. ionic 上拉菜单(ActionSheet) 上拉菜单(ActionSheet) ...
- Android中GridView滚动到底部加载数据终极版
之前在项目中有一个需求是需要GridView控件,滚动到底部自动加载.但是呢GridView控件并不提供诸如ListView监听滚动到底部的onScrollListener方法,为了实现这样一个效果, ...
- ionic上拉加载更多解决方法
第一步: $scope.hasmore = true;//是否允许上拉加载 $scope.num = 8;//显示条数 第二步://查询显示内容,查出所有的 $scope.Group = functi ...
- ionic上拉加载组件 ion-infinite-scroll自动调用多次的问题
参考文章地址:http://www.cnblogs.com/luleixia/p/6402418.html ionic 一个上拉刷新的组件 ion-infinite-scroll,如果页面未填充满页面 ...
- 解决ionic 上拉加载组件 ion-infinite-scroll自动调用多次的问题或禁止第一次加载
ionic 中一个上拉刷新的组件 ion-infinite-scroll,如果页面未填充满页面高度,会自动检测并无限调用多次加载更多的函数: 当然,主要会导致首次调用的时候,会执行几次加载更多的函数: ...
- 解决ionic 上拉加载组件 ion-infinite-scroll自动调用多次的问题
ionic 中一个上拉刷新的组件 ion-infinite-scroll,如果页面未填充满页面高度,会自动检测并无限调用多次加载更多的函数:当然,主要会导致首次调用的时候,会执行几次加载更多的函数: ...
- ionic 上拉加载问题(分页)
问题描述: 1.第一初始化时执行了上拉加载更多. 2.上拉时存在执行多次加载动作. angularjs的ajax不提供同步机制,是为了防止页面长时间等待,很多时候我们又需要这种同步机制交换状态,比如上 ...
随机推荐
- 使用CSS3实现百叶窗
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title&g ...
- Shrink磁盘
30857(分区的总容量) = 10160(可修改的这个10610表示Shrink之后的空闲分区) + 20697(Shrink之后分区中占用掉的容量)
- JAVA图片相关
有些图片后缀为jpg,但是实际格式却不是jpg,通过url下载图片字节.然后用ImageIO读取时,出现返回null的情况.出现这种情况,就需要使用webp-imageio.jar.(https:// ...
- PHP 开发 APP 接口 学习笔记与总结 - APP 接口实例 [3] 首页 APP 接口开发方案 ② 读取缓存方式
以静态缓存为例. 修改 file.php line:11 去掉 path 参数(方便),加上缓存时间参数: public function cacheData($k,$v = '',$cacheTim ...
- php实现多任务并发探讨
如果是后台任务,需要通过队列转换为异步执行 如果是网络任务,可以使用socket_select 或者stream_select来执行(基于select模型) 如果一定要使用多线程可以安装多线程扩展,用 ...
- HOSTS文件详解【win|mac】
hosts文件是一个用于储存计算机网络中各节点信息的计算机文件.这个文件负责将主机名映射到相应的IP地址. hosts文件通常用于补充或取代网络中DNS的功能.和DNS不同的是,计算机的使用者可以直接 ...
- 郎科U208(主控 PS2251-50 HYNIX H27UCG8T2MYR)量产还原
6年前的一个U盘 记得还是参加某会议送的,当时做了量产 多做了一个光盘区,现在用不着了 想还原成普通U盘 忘了方法. 可见笔记的重要性 Chipgenius看了主控 PS2251-50 芯片是海力士 ...
- Defining Stored Programs
ok DROP PROCEDURE IF EXISTS truncate_insert_rank_month; DELIMITER /w/ CREATE PROCEDURE truncate_inse ...
- reduce()
Professional.JavaScript.for.Web.Developers.3rd.Edition.Jan.2012 var value = [1,2,3,4,5]; var sum = v ...
- TabHost详解
[转]http://blog.csdn.net/harvic880925/article/details/17120325 前言:今天仔细研究了下TabHost,主要是为了实现微信底部导航栏的功能,最 ...