apicloud实现分页加载数据

html页面

<div id="content">
    </div>
    <div onclick="show()">继续加载</div>

    <!-- 模板 -->
    <script id="articleTemp" type="text/x-dot-template">
        {{~it:value:index}}
            <div onclick='showById("{{= value.id }}")'>
                {{= index+1 }}.{{= value.title }}&nbsp;&nbsp;{{= value.creatorName }}==={{= value.viewNum }}
            </div>
        {{~}}
    </script>

js代码

apiready = function(){
    show();
};

var limit=3;//每次查询的记录数
var skip=0;//跳过的记录数
function showArticleList(){
        var client = new Resource(APP_INFO.app_id, APP_INFO.app_key);
        var Model = client.Factory("article");
        Model.query({
            "filter":{
                "fields":{"id": true, "title": true, "viewNum": true,"creatorName": true},//或者["id","make","model"]
                "where":{
                            "status":1,
                            //"title":{"like":"马.*"}
                        },//status列的记录是1的,全部查询
                "order": "viewNum DESC",
                "skip":skip,
                "limit":limit
            }
        }, function(ret,err){
            if(err){
                //处理错误 err

            }else{
                //处理数据 ret
                alert(JSON.stringify(ret));

                var interation = doT.template( $('#articleTemp').html() );
                //将数据显示到网页中
                $( '#content' ).append(interation( ret ));
            }
        })
    }
function show(){
    showArticleList();
    skip=skip+limit;//每次查询后都增加跳过的记录数
}

原文出处:https://malaoshi.top/show_1EFAW4mYAMm.html