apiCloud实现加载更多效果

1.接口支持,加入参数page。

$page = $this->_request('page','trim','1');
$pagesize = 10; // 默认获取10条

2.利用limit获取数据

select * from sh_category limit 20;
select * from sh_category limit 0,10; // 第一页
select * from sh_category limit 10,10;// 第二页

程序处理

$goods = $this->where($where)->limit(($page-1)*$num,$num)->order($order)->select();

第一页,就是从0,10。第二页,就是10,10。

3.接口提示下一页是否有数据,以及当前页

$this->outData['status'] = '1';
$this->outData['msg']    = '获取成功';
$this->outData['info']['goods']   = $goods;
$this->outData['info']['page']   = $page;
$this->outData['info']['category_id']  = $category_id;
if (count($next_page_goods) > 0) {$this->outData['info']['next'] = '1'; // 还有数据
} else {$this->outData['info']['next'] = '0'; // 已经没有数据
}

4.前端通过doT处理

<div id="info_area"></div>
<script id="info_tmpl" type="text/x-dot-template">
{{? typeof it.goods != 'undefined'}}<div id="goods_data" class="aui-content"><ul class="aui-list aui-media-list">{{~ it.goods:gval:gkey}}<li class="aui-list-item" onclick="openGoodsDetail('{{= gval.name}}','{{= gval.id}}')"><div class="aui-media-list-item-inner"><div class="aui-list-item-media"><img src="{{= gval.logoimg}}"></div><div class="aui-list-item-inner"><div class="aui-list-item-text"><div class="aui-list-item-title">{{= gval.name}}</div></div><div class="red">¥{{= gval.price}}</div><div class="aui-list-item-text"><div class="aui-list-item-title" style="text-decoration:line-through;">¥{{= gval.oprice}}</div><div class="aui-list-item-right">已售{{= gval.salecount}}件</div></div></div></div></li>{{~ }}</ul></div>{{? it.next == '1'}}<div id="more" onclick="ajaxGetMore('{{= it.category_id}}','{{= parseInt(it.page)+1}}')" style="margin: 15px;color:gray;text-align: center;">加载更多</div>{{??}}<div id="none" style="margin: 15px;color:gray;text-align: center;">没有了</div>{{?}}
{{?? }}<div style="margin-top:20px;text-align: center;color:gray;">暂无数据</div>
{{?}}
</script>

这里有个ajaxGetMore方法。处理加载更多数据。

设置一个base_area,专门装填上一页的数据。下一页的数据,继续在info_area中展示。

<div id="base_area" class="aui-content">
</div>
1)默认的ajax获取第一页数据js
// 获取分类商品信息api.ajax({url: BASE_SH_REQUEST_URL+'/?g=Api&m=Goods&a=getCategoryOptimizedGoods',method: 'get',data: {values: {category_id: category_id}}}, function(json, err) {if (json.status == '1' || json.status == '4') {var interText = doT.template($("#info_tmpl").text());$("#info_area").html(interText(json.info));} else {var toast = new auiToast();toast.fail({title: json.msg,duration: 2000});}});
2)ajaxGetMore获取更多js
// 获取更多
// page为下一页的数值
function ajaxGetMore(category_id,page) {var base_area = $api.byId('base_area'); var goods_data= $api.byId('goods_data');$api.append(base_area,$api.html(goods_data));api.ajax({url: BASE_SH_REQUEST_URL+'/?g=Api&m=Goods&a=getCategoryOptimizedGoods',method: 'get',data: {values: {category_id: category_id,page:page,}}}, function(json, err) {if (json.status == '1' || json.status == '4') {var interText = doT.template($("#info_tmpl").text());$("#info_area").html(interText(json.info));} else {var toast = new auiToast();toast.fail({title: json.msg,duration: 2000});}});
}

核心就在这里

var base_area = $api.byId('base_area');
var goods_data= $api.byId('goods_data');
$api.append(base_area,$api.html(goods_data));

每次点击加载更多,都向base_area区域中把上一页的goods_data数据填入。通过append方法,可以很好的处理这种填入效果。

append,描述:在DOM元素内部,最后一个子元素后面插入HTML字符串。

html,描述:获取或设置DOM元素的innerHTML。

基本完美~

apiCloud实现加载更多效果,基本完美~相关推荐

  1. JS 判断滚动底部并加载更多效果。。。。。。。。。

    JS 判断滚动底部并加载更多效果......... <html lang="zh-cn"> <head> <meta http-equiv=" ...

  2. jquery实现加载更多效果

    情况是当滑动条滑动到最底部的时候,数据显示出一部分的更多 思路:获取到浏览器屏幕的高度client,文档的高度h和滑动距离顶部的距离scroll,当h<=client+scroll的时候就是滑动 ...

  3. Android无限滚动库mugen实现加载更多效果

    github:https://github.com/vinaysshenoy/mugen 效果图: 例子中结合使用了 SwipeRefreshLayout 和 RecyclerView 使用很简单 1 ...

  4. 下滑加载更多js_vue.js怎么实现滑动到底部加载更多数据效果?

    vue.js怎么实现滑动到底部加载更多数据效果?下面本篇文章给大家简单介绍一下vue实现滑动到底部加载更多效果.有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助. 本文实例为大家分享了v ...

  5. dede文章异步ajax加载,织梦DedeCMS列表“加载更多”“无限下拉”Ajax加载使用方法...

    Infinite Ajax Scroll 简称 ias,无限的ajax滚动,是一款jQuery滚动ajax分页插件,当页面滚动到容器可见部分将自动异步加载数据. 下面先来看看效果. 无限下拉效果 点击 ...

  6. 使用SwipeRefreshLayout和RecyclerView实现仿“简书”下拉刷新和上拉加载更多

    原文地址: http://blog.csdn.net/leoleohan/article/details/50989549/ 一.概述 我们公司目前开发的所有Android APP都是遵循iOS风格设 ...

  7. android 刷新某条数据_Android 支持刷新、加载更多、带反弹效果的RecyclerView

    点击上方"Android技术杂货铺",选择"标星" 干货文章,第一时间送达! 开篇 当前市面上很多支持刷新.加载更多RecyclerView开源库,为何我这里还 ...

  8. ASP.NET仿新浪微博下拉加载更多数据瀑布流效果

    闲来无事,琢磨着写点东西.貌似页面下拉加载数据,瀑布流的效果很火,各个网站都能见到各式各样的展示效果,原理大同小异.于是乎,决定自己写一写这个效果,希望能给比我还菜的菜鸟们一点参考价值.       ...

  9. php ajax 上拉显示更多,PHP+Ajax点击加载更多内容 -这个效果好,速度快,只能点击更多加载,不能滚动自动加载...

    这个效果好,速度快,只能点击更多加载,不能滚动自动加载 一.HTML部分 ::点击加载更多内容:: 引入jQuery插件和jquery.more.js加载更多插件 jQuery $(function( ...

最新文章

  1. VOA AGRICULTURE REPORT - Two Efforts Seek to Increase Food Security in Africa
  2. 前端学习(239):渐进增强和优雅降级
  3. 群赛 ZOJ3741(dp) ZOJ3911(线段树)
  4. spring cron表达式(定时器)
  5. 李迟2021年4月知识总结
  6. CString Format
  7. JAVA Excel com组件_jacob java调用com组件基础运用
  8. NYOJ 个人刷题题解
  9. Axis1.4容器WebService服务发布过程
  10. Ubuntu关闭cups打印机服务
  11. win10打开命令提示符
  12. nrg文件是什么?nrg文件格式详细介绍
  13. 网盘上传文件服务器失败原因,win7系统在百度网盘上传文件一直失败的解决方法...
  14. ElasticSearch聚合分析API
  15. AI期末考试基础知识点复习(AI入门)
  16. TIOBE 3 月编程语言排行榜刚刚出炉
  17. Word~Word修改行间距磅值
  18. 微信小程序 右上角分享 实现代码
  19. 2022第五空间网络安全大赛
  20. Pthreads并行编程之spin lock与mutex性能对比分析(转)

热门文章

  1. Word 2003中打开最近操作过的文档的两种推荐的方法
  2. es5.4.0-CentOS-6.5-x86_64安装文档
  3. js swipe 图片滑动控件实现 任意尺寸适用任意屏幕
  4. 微信支付 支付成功后不跳转 ecshop微信支付 如下操作即可
  5. .net mvc 获取url中controller和action
  6. 推荐一些好书(PHP方向)
  7. 虚函数virtual
  8. 国密算法-商密认证-硬件加密-同方TF32A09-32位高速加密芯片
  9. Silverlight开发之MVVM模式
  10. android-- apktool反编译工具使用详解