首先下拉刷新的代码是这样的,标红的地方为关键代码

<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 上拉加载更多&瀑布流加载&滚动到底部加载更多 主意事项的更多相关文章

  1. XRecyclerView:实现下拉刷新、滚动到底部加载更多以及添加header功能的RecyclerView

    介绍: 一个实现了下拉刷新,滚动到底部加载更多以及添加header功能的的RecyclerView.使用方式和RecyclerView完全一致,不需要额外的layout,不需要写特殊的adater. ...

  2. 滚动到底部加载更多及下拉刷新listview的使用

    最新内容建议直接访问原文:滚动到底部加载更多及下拉刷新listview的使用 本文主要介绍可同时实现下拉刷新及滑动到底部加载更多的ListView的使用. 该ListView优点包括:a. 可自定义下 ...

  3. ionic-Javascript:ionic 上拉菜单(ActionSheet)

    ylbtech-ionic-Javascript:ionic 上拉菜单(ActionSheet) 1.返回顶部 1. ionic 上拉菜单(ActionSheet) 上拉菜单(ActionSheet) ...

  4. Android中GridView滚动到底部加载数据终极版

    之前在项目中有一个需求是需要GridView控件,滚动到底部自动加载.但是呢GridView控件并不提供诸如ListView监听滚动到底部的onScrollListener方法,为了实现这样一个效果, ...

  5. ionic上拉加载更多解决方法

    第一步: $scope.hasmore = true;//是否允许上拉加载 $scope.num = 8;//显示条数 第二步://查询显示内容,查出所有的 $scope.Group = functi ...

  6. ionic上拉加载组件 ion-infinite-scroll自动调用多次的问题

    参考文章地址:http://www.cnblogs.com/luleixia/p/6402418.html ionic 一个上拉刷新的组件 ion-infinite-scroll,如果页面未填充满页面 ...

  7. 解决ionic 上拉加载组件 ion-infinite-scroll自动调用多次的问题或禁止第一次加载

    ionic 中一个上拉刷新的组件 ion-infinite-scroll,如果页面未填充满页面高度,会自动检测并无限调用多次加载更多的函数: 当然,主要会导致首次调用的时候,会执行几次加载更多的函数: ...

  8. 解决ionic 上拉加载组件 ion-infinite-scroll自动调用多次的问题

    ionic 中一个上拉刷新的组件 ion-infinite-scroll,如果页面未填充满页面高度,会自动检测并无限调用多次加载更多的函数:当然,主要会导致首次调用的时候,会执行几次加载更多的函数: ...

  9. ionic 上拉加载问题(分页)

    问题描述: 1.第一初始化时执行了上拉加载更多. 2.上拉时存在执行多次加载动作. angularjs的ajax不提供同步机制,是为了防止页面长时间等待,很多时候我们又需要这种同步机制交换状态,比如上 ...

随机推荐

  1. cookie 换肤

    jquery.Cookies.js /** * Cookie plugin * * Copyright (c) 2006 ziqiu.zhang * Dual licensed under the M ...

  2. javascript中的function

    function / 对象 所有的变量和方法名的:以字母,$ _开头其他随便,尽量使用英文字母命名,见名知意注意点:不允许使用关键字定义变量和方法的名称====函数即方法,方法即函数====百度:ja ...

  3. win7(32/64)+apache2.4+php5.5+mysql5.6 环境搭建配置

        引用自:http://blog.csdn.net/z_cf1985/article/details/22454749 环境:win7 32.(64位的同理,下载相关软件必须是对应的64位版本) ...

  4. 如何用JavaScript在页面上显示一个时间钟表

    <html><head><script type="text/javascript">function myTime(){var today=n ...

  5. MarkDown编辑器用法

    代码行1 var s = "JavaScript syntax highlighting"; alert(s); 代码行2:ESC下面的英文3个波浪号~按键 var s = &qu ...

  6. 《Pro Git》笔记1:起步

    第一章 起步 1.关于版本控制 版本控制用于记录和追踪目录结构和文件内容变化,能够追溯过去的任何修改和变化,并恢复到任何历史状态. 版本控制系统可以按照发展过程分成以下几类: 目录备份.记录版本变化最 ...

  7. ThinkPHP 3.2 版本升级了哪些内容

    ThinkPHP 3.2 版本升级了哪些内容           ThinkPHP 3.2发布了挺长时间了,这里也总结下这次ThinkPHP 3.2到底发生了哪些变化,方便程序员们进行开发. 前言 T ...

  8. LR动态脚本的处理

    在处理SSO修改密码脚本时遇到一个问题,根据用户名的不同,提交请求中数据会不一样.处理此问题,如果经分析用同类型的账号(每个账号含有的子账号类型和数目一致)测试与实际不同类型账号性能没有大的差别,则用 ...

  9. 去除字符串中空格的方法(2016.1.12P141-2)

    // forif来处理空格 // 方法一 String str = " ww sse rr"; String str1;// 定义一个中间变量 String str2 = &quo ...

  10. JBPM3.2 TABLE

    http://m.blog.csdn.net/blog/longjie_happy/9343349