做app项目积分商城的商品列表需要分页显示

实现:

  ionic滚动条:ion-scroll 用于创建一个可滚动的容器。

  附:菜鸟教程:http://www.runoob.com/ionic/ionic-scroll.html

    隶属于ionContent 或 ionScroll,要写在ion-content才有效

ion-infinite-scroll

当用户到达页脚或页脚附近时,ionInfiniteScroll指令允许你调用一个函数 。

当用户滚动的距离超出底部的内容时,就会触发你指定的on-infinite。

ion-refresher

允许你添加下拉刷新滚动视图。

<!-- <ion-refresher> 下拉刷新指令  -->
<ion-refresher pulling-text="Pull to refresh" on-refresh="doRefresh()"></ion-refresher> <!-- ion-infinite-scroll 上拉加载数据指令 distance默认1% nf-if的值为false时,就禁止执行on-infinite -->
<ion-infinite-scroll ng-if="moredata" on-infinite="loadMore()" distance="1%" ></ion-infinite-scroll>

  1. on-refresh 下拉触发的函数 函数执行结束之前必须广播下该事件结束 $scope.$broadcast('scroll.refreshComplete');

     2. on-infinite 上拉触发的函数 同样需要广播事件结束 $scope.$broadcast('scroll.infiniteScrollComplete');

js代码:

     //加载更多
// $scope.items = [];
//无限加载
$scope.moredata = true; var sName = "''";//初始化搜索条件,默认
var currentPage = 0;//初始化页码
var intData = [];//初始化数组 //搜索事件
$scope.search = function() {
if($scope.searchName != undefined && $scope.searchName != "" && $scope.searchName != null) {
sName = $scope.searchName;
currentPage = 0;
// intData = [];
intData.splice(0,intData.length);//清空数组
$scope.loadMore();
}
} //下拉刷新
$scope.doRefresh = function() {
currentPage = 1;
intData = [];
$scope.moredata = true;
// $scope.loadMore();
HttpRequest.query("jdApi/commodity/getCommodityList/" + currentPage + "/" + sName + "/''", true)
.success(function(objs) {
var result = angular.fromJson(objs.jdBaseMsgBean.result); //获取数据,在原来的数据基础上追加信息
var lists = intData;
if(lists.length > 0 ){
intData = new Array().concat(lists, result.data);
}else{
intData = result.data;
}
$scope.gifts = intData; if(result.totalRecord <= currentPage*result.pageSize) {
$scope.moredata = false;
}
//自动请求后台多次问题解决
$timeout(function () {
$scope.$broadcast('scroll.refreshComplete');
}, 1000);
}); } //上拉加载
$scope.loadMore = function() {
// $http.get('/more-items').success(function(items) {
// useItems(items);
// $scope.$broadcast('scroll.infiniteScrollComplete');
// });
currentPage += 1;
HttpRequest.query("jdApi/commodity/getCommodityList/" + currentPage + "/" + sName + "/''", true)
.success(function(objs) {
var result = angular.fromJson(objs.jdBaseMsgBean.result); //获取数据,在原来的数据基础上追加信息
var lists = intData;
if(lists.length > 0 ){
intData = new Array().concat(lists, result.data);
}else{
intData = result.data;
}
$scope.gifts = intData; if(result.totalRecord <= currentPage*result.pageSize) {
$scope.moredata = false;
}
// if(result.totalPage == currentPage) {
// $scope.moredata = false;
// }
// if(result.data.length < result.pageSize){
// $scope.moredata = false;
// } // $scope.$broadcast('scroll.infiniteScrollComplete');
//自动请求后台多次问题解决--ionic 上拉刷新 ion-infinite-scroll 自动调用多次问题解决
timer = $timeout(function () {
$scope.$broadcast('scroll.infiniteScrollComplete');
}, 1000);
});
} $scope.$on('$stateChangeSuccess', function() {
$scope.loadMore();
}); $scope.$on("$destroy", function () {
//清除配置,不然scroll会重复请求
$timeout.cancel(timer);
});

说明:

  1.moredata,页面用ng-if="moredata",来判断是否加载数据。当滚动条到底部,并且服务器没有数据的时候,使用ng-if指令来控制便签是否存在,即,是否继续向服务器发送请求(如果没有这个功能,会不停的向服务器发送请求)。

  2.$scope.$on上的$stateChangeSuccess和$destroy

      如果在下拉标签中使用immediate-check="false"属性的话

<ion-infinite-scroll immediate-check="false" ng-if="moredata" on-infinite="loadMore()" distance="1%"></ion-infinite-scroll>

      $stateChangeSuccess配置是数据加载:是否在页面加载后立刻触发on-infinite的方法,设为false后,则只有滚动到页面边缘时才会触发,即使页面加载出来已经到最底部,不滚动一下的话也是不会触发的。

  3.HttpRequest.query("jdApi/commodity/getCommodityList/" + currentPage + "/" + sName + "/''", true)是service层封装的$http服务,如下

 query: function(url, isLoad){
if(isLoad){
Prompt.showLoading();
}
var params = {"rd": angular.randomCode()};
var http = $http({
method: 'QUERY',
params: params,
url: $rootScope.url.app + 'services/' + url,
timeout:90000
});
http.error(function(data, status, headers, config){
showError(status);
});
http.finally(function(){
if(isLoad){
Prompt.hideLoading();
}
});
return http;
}

html代码:

 <ion-content class="divider-bg box-content" style="">
<ion-refresher pulling-text="下拉刷新" on-refresh="doRefresh()"></ion-refresher>
<ion-list>
<ion-item class="item-thumbnail-left item-thumbnail-left-custom item-icon-right" ng-repeat="g in gifts" href="#/tab/my/jifen/gift/{{totalScore}}/{{g.id}}">
<img class="img-48 media-object pull-left" ng-src="http://img13.360buyimg.com/n4/{{g.imagePath}}" alt="{{g.name}}">
<h2>{{g.name}}</h2>
<div class="shop-pro-list">
<span class="shop-pro-list-scores"><span class="color-org">{{g.price}}</span>{{'jifen.jifen' | i18next}}</span>
<span><i class="exchange-btn">{{'jifen.exchangeNow' | i18next}}</i></span>
</div>
</ion-item>
</ion-list>
<ion-infinite-scroll ng-if="moredata" on-infinite="loadMore()" distance="1%"></ion-infinite-scroll>
</ion-content>

搜索的代码:

<button class="button button-small button-search-jd" on-tap="search()">{{'jifen.search' | i18next}}</button>

解释:on-tap为ionic事件(手势轻击事件)

  ionic手势事件:http://www.runoob.com/ionic/ionic-gesture-event.html

    起初使用ng-click,但事件不起作用,通过查找发现:直接在ion-list中的ion-item中并不能触发ng-click事件,可以在item中的元素上再套一层div。

    Ionic 常见问题及解决方案:https://www.jianshu.com/p/b567cc657a49

注:分页参考文档

https://blog.csdn.net/jslcylcy/article/details/76633635
https://www.cnblogs.com/dreamowneryong/p/4969264.html

ionic 上拉刷新 ion-infinite-scroll 自动调用多次问题解决
  加入定时器timer:https://blog.csdn.net/chenhua4088/article/details/49929279

ionic 的下拉刷新 与 上拉加载:https://www.cnblogs.com/ailen226/p/4626166.html

列表展示页面,分页数据进行追加:http://hbiao68.iteye.com/blog/2295161

angularjs+ionic的app端分页和条件的更多相关文章

  1. AngularJS中实现服务端分页

    这个教程将介绍在AngularJS应用中的服务端分页处理.在任何涉及到列表或表格数据的应用中都可能会用到分页. 概念 当我们处理异步分页时,每次只从服务器上获取一页数据.也就是说当用户点击第二页,就只 ...

  2. 前端实现搜索历史和清空历史(angularjs+ionic)

    要实现的页面效果: 1.显示历史搜索, 2.最近搜索的排在最前, 2.最多显示8条历史 4.清空历史记录 思路: 1.首先显示历史记录需要一个数组searchItems,通过ng-repeat显示每一 ...

  3. Angularjs的真分页,服务端分页,后台分页的解决方案

    背景:项目的框架使用的是Angularjs,在做数据展示的时候,使用的是ng-table.用过ng-table的人都知道,他是自带分页的,默认分页方式是假分页.也就是一口气把所有的数据从数据库里取出来 ...

  4. Ionic——下一代 APP 开发框架

    http://www.tuicool.com/articles/iY3ENvY 最近 Facebook React 团队释出了 React Native, 用来构建 Mobile Native 应用. ...

  5. asp.net mvc bootstrap datatable 服务端分页

    datatable 服务端分页 因项目需求变动,需处理大量数据,更改成服务端分页,自己两天的学习笔记 先上图[ jqueryui风格] 前端代码: @{ Layout = null;} <!DO ...

  6. asp.net mvc bootstrap datatable 服务端分页 更新槽糕的代码【1】

    datatable 服务端分页 因项目需求变动,需处理大量数据,更改成服务端分页,自己两天的学习笔记 datatable 1.10.7 百度云下载  密码:0ea1 先上图[ jqueryui风格] ...

  7. 搭建 AngularJS+Ionic+Cordova 开发环境并运行一个demo

    目前的手机APP有三类:原生APP,WebAPP,HybridApp:HybridApp结合了前两类APP各自的优点,越来越流行. Cordova就是一个中间件,让我们把WebAPP打包成Hybrid ...

  8. springboot+layui实现PC端用户的增删改查 & 整合mui实现app端的自动登录和用户的上拉加载 & HBuilder打包app并在手机端下载安装

    springboot整合web开发的各个组件在前面已经有详细的介绍,下面是用springboot整合layui实现了基本的增删改查. 同时在学习mui开发app,也就用mui实现了一个简单的自动登录和 ...

  9. AngularJS+Ionic开发-1.搭建开发环境

    临时项目需要使用AngularJS+Ionic+Cordova技术,半年前跟别人用过一段时间做过几个页面,目前别人已经无法联系了,只能我自己上了. 上次做完项目后,想抽时间好好巩固一下这方面的知识面来 ...

随机推荐

  1. Mysql编译安装详解

    wget http://mirrors.cnnic.cn/apache/httpd/mysql-5.5.20.tar.gz root@Mysql-server ~]# yum install -y c ...

  2. dubbo的InvocationChain

    个人觉得dubbo比较好的设计是:一个是Cooma微容器设计.另一个就是InvocationChain了 Cooma微容器是自己实现了一套SPI,方便了用户做扩展: InvocationChain类似 ...

  3. c#**************

    ddfbvbb c v我wossssssss

  4. python当中的 可迭代对象 迭代器

    学习python有一段时间了,在学习过程中遇到很多难理解的东西,做一下总结,希望能对其他朋友有一些帮助. 完全是个人理解,难免有错,欢迎其他大神朋友们批评指正. 1 迭代 什么是迭代呢??我们可以这样 ...

  5. Tcl与Design Compiler (五)——综合库(时序库)和DC的设计对象

    本文如果有错,欢迎留言更正:此外,转载请标明出处 http://www.cnblogs.com/IClearner/  ,作者:IC_learner 前面一直说到综合库/工艺库这些东西,现在就来讲讲讲 ...

  6. JavaScript 对图像进行(追加,插入,替换,删除)

    JavaScript 对图像进行(追加,插入,替换,删除) 本次所学内容: document.querySelector('.container') 这个是可以查找单个[id标签和class标签] d ...

  7. jquery中的attr()与prop()的区别

    根据官方的建议:具有 true 和 false 两个属性的属性,如 checked, selected 或者 disabled 使用prop(),其他的使用 attr()

  8. ubuntu12.04更新到14.04,win7误删BCD引导项,导致两个系统都无法进入

    解决办法: 制作老毛桃U盘启动盘,使用BCD编辑软件,对C/boot下的BCD文件进行编辑,添加win7引导向. 开机进入win7后,使用easyBCD添加ubuntu14.04启动项,选择grub2 ...

  9. 【linux之压缩归档,tar】

    一.压缩和归档 压缩算法就是等量代换 gzip FILE1 FILE2... 扩展名 .gz -#(数字):#代表压缩等级,1-9,默认6 -d(compression):解压缩 -r:递归的压缩目录 ...

  10. 关于wooyun-2015-096990的总结

    漏洞url:http://wooyun.jozxing.cc/static/bugs/wooyun-2015-096990.html 摘要 if(!ini_get('register_globals' ...