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. JS实现点击加载更多效果

    适用场景:后端直接把所有的文章都给你调出来了,但是领导又让做点击加载更多效果...(宝宝心里苦啊)   点击加载更多效果:         第一个和第二个参数分别是btn和ul的DOM(必填)     ...

  3. jquery实现加载更多效果

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

  4. ajax 下拉加载更多效果

    1.生成HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...

  5. 基于jQuery实现点击列表加载更多效果

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head>   < ...

  6. vue2.0 自定义 下拉刷新和上拉加载更多(Scroller) 组件

    1.下拉刷新和上拉加载更多组件 Scroller.vue <!-- 下拉刷新 上拉加载更多 组件 --> <template> <div :style="mar ...

  7. 实现上拉加载更多的SwipeRefreshLayout

    转载请标明出处: http://blog.csdn.net/developer_jiangqq/article/details/49992269 本文出自:[江清清的博客] (一).前言: [好消息] ...

  8. apicloud如何实现优雅的下拉刷新与加载更多

    apicloud中提供下拉刷新监听事件api,也提供滚动到底部事件的监听,能够实现下拉刷新和滚动到底部加载更多功能,但是我们真的就满足实现功能了吗?将两个代码拼凑起来运行看看发现了什么?是的,在滚动到 ...

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

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

随机推荐

  1. hdu2767 Proving Equivalences,有向图强联通,Kosaraju算法

    点击打开链接 有向图强联通,Kosaraju算法 缩点后分别入度和出度为0的点的个数 answer = max(a, b); scc_cnt = 1; answer = 0 #include<c ...

  2. UESTC--1262--Memory(dfs)

    Memory Time Limit: 1000MS   Memory Limit: 65535KB   64bit IO Format: %lld & %llu SubmitStatus De ...

  3. Oracle实例和Oracle数据库(Oracle体系结构)---转载

    对于初接触Oracle 数据库的人来讲,很容易混淆的两个概念即是Oracle 实例和Oracle 数据库.这两 概念不同于SQL sever下的实例与数据库,当然也有些相似之处.只是在SQL serv ...

  4. 杂项-软件: VBA(Visual Basic for Applications)

    ylbtech-杂项-软件: VBA(Visual Basic for Applications) VBA (Visual Basic宏语言) Visual Basic for Application ...

  5. Spark RDD概念学习系列之Pair RDD的transformation操作

    不多说,直接上干货! Pair RDD的transformation操作 Pair RDD转换操作1 Pair RDD 可以使用所有标准RDD 上转化操作,还提供了特有的转换操作. Pair RDD转 ...

  6. js闭包概念

    含义:闭包是一个概念,它描述了函数执行完毕内存释放后,依然内存驻留的一个现象,只要把握这个核心概念,闭包就不难理解了 function a(){      var i=0;      function ...

  7. IOS入门之创建视图和控件绑定

    学习IOS几天了,跟着教程做了两个小应用了,现在先来总结一下.今天就是创建视图和绑带到代码了.其实就是常见的MVC模式实现. 使用的Xcode版本是8.2. 在Xcode创建项目之后,默认就会创建一个 ...

  8. ndis6 how to drop packets

    In ndis6 how to drop packets? in FilterSendNetBufferLists: FILTER_RELEASE_LOCK(&pFilter->Lock ...

  9. (1)安装vagrant和virtualbox

    使用xshell,学校服务器需要先联外网. 1.安装Linux头包(linux-header package): # #yum install kernel-devel 2.安装virtualbox. ...

  10. BZOJ 3295 [CQOI2011]动态逆序对 (三维偏序CDQ+树状数组)

    题目大意: 题面传送门 还是一道三维偏序题 每次操作都可以看成这样一个三元组 $<x,w,t>$ ,操作的位置,权值,修改时间 一开始的序列看成n次插入操作 我们先求出不删除时的逆序对总数 ...