获取数据含分页

var gmuip = {};

gmuip.ajax = function (obj) {

    var action = obj.action;

    var param = obj.param;

    var call = obj.call;

    var callfalse = obj.callfalse;

    this.request = function () { app.post(action, param, call, callfalse) };

}

gmuip.ajax.prototype =

{

    setlistener: function (request) {

        document.addEventListener("deviceready", request, true);

    }

}

var bt = baidu.template;

gmuip.tesppost =

{

    GetApplayList: function (Action, PageIndex, PageSize, Order, JsonWhere, SSO) {

        var obj = new Object();

        obj.action = Action;

        obj.param = { "PageIndex": PageIndex, "PageSize": PageSize, "Order": Order, "JsonWhere": JsonWhere, "SSO": SSO };

        obj.call = function (data) {

            var returnData = data.returnValue.replace(/[\r\n]/g, "").replace("<?xml version=\"1.0\" encoding=\"utf-8\"?><string xmlns=\"http://tempuri.org/\">", "").replace("</string>", "");

            var ApplayData = $.parseJSON(returnData).ReturnResult;

            var html = bt('applaylist', ApplayData);

            if (ApplayData.DataList.length < $("#pagesize").val()) {

                $("#load_add").hide();

            }

            if (ApplayData.DataPagination.Totalrow > 0) {

                if (parseInt($("#pageindex").val()) > 1) {

                    $("#theapplaylist").append(html);

                }

                else {

                    $("#theapplaylist").empty().html(html);

                }

                //计算页数

                var pagecount = parseInt(ApplayData.DataPagination.Totalrow) / PageSize;

                $("#pagecount").val(pagecount);

            } else {

                $("#theapplaylist").empty().append("暂无数据...");

            }

            app.progress.stop();

            ui.init();

        };

        var ajaxs = new gmuip.ajax(obj);

        ajaxs.setlistener(ajaxs.request);

    },

    GetQuestionList: function (Action, PageIndex, PageSize, Order, JsonWhere, SSO) {

        var obj = new Object();

        obj.action = Action;

        obj.param = { "PageIndex": PageIndex, "PageSize": PageSize, "Order": Order, "JsonWhere": JsonWhere, "SSO": SSO };

        obj.call = function (data) {

            var returnData = data.returnValue.replace(/[\r\n]/g, "").replace("<?xml version=\"1.0\" encoding=\"utf-8\"?><string xmlns=\"http://tempuri.org/\">", "").replace("</string>", "");

            var QuestionData = $.parseJSON(returnData).ReturnResult;

            var html = bt('questionlist', QuestionData);

            if (QuestionData.DataList.length < $("#pagesize").val()) {

                $("#load_add").hide();

            }

            if (QuestionData.DataPagination.Totalrow > 0) {

                if (parseInt($("#pageindex").val()) > 1) {

                    $("#thequestionlist").append(html);

                }

                else {

                    $("#thequestionlist").empty().html(html);

                }

                //计算页数

                var pagecount = parseInt(QuestionData.DataPagination.Totalrow) / PageSize;

                $("#pagecount").val(pagecount);

            } else {

                $("#thequestionlist").empty().append("暂无数据...");

            }

            app.progress.stop();

            ui.init();

        };

        var ajaxs = new gmuip.ajax(obj);

        ajaxs.setlistener(ajaxs.request);

    },

    PullNextPage: function (pullgetdata) {

        var myScroll,

    pullUpEl, pullUpOffset,

        pullUpEl = document.getElementById('pullUp');

        pullUpOffset = pullUpEl.offsetHeight;

 

        myScroll = new iScroll('wrapper', {

            useTransition: true,

            checkDOMChanges: true,

            onRefresh: function () {

                if (pullUpEl.className.match('loading')) {

                    pullUpEl.className = '';

                    pullUpEl.querySelector('.pullUpLabel').innerHTML = '向上拖动刷新...';

                }

            },

            onScrollMove: function () {

                if (this.y < (this.maxScrollY - 5) && !pullUpEl.className.match('flip')) {

                    pullUpEl.className = 'flip';

                    pullUpEl.querySelector('.pullUpLabel').innerHTML = '松开刷新...';

                    this.maxScrollY = this.maxScrollY;

                } else if (this.y > (this.maxScrollY + 5) && pullUpEl.className.match('flip')) {

                    pullUpEl.className = '';

                    pullUpEl.querySelector('.pullUpLabel').innerHTML = '向上拖动刷新...';

                    this.maxScrollY = pullUpOffset;

                }

            },

            onScrollEnd: function () {

                if (pullUpEl.className.match('flip')) {

                    pullUpEl.className = 'loading';

                    pullUpEl.querySelector('.pullUpLabel').innerHTML = 'Loading...';

                    var Pagecount = parseInt($("#pagecount").val());

                    if (parseInt($("#pageindex").val()) <= Pagecount) {       //当前页码必须小于或等于总页数-1,页码下标从0开始

                        var pageindex = parseInt($("#pageindex").val()) + 1;

                        $("#pageindex").val(pageindex); //触发翻页事件,当前页数加1并保存

                        pullgetdata();        //当"向上拖动刷新..."事件触发后,加载该方法,请求服务并加载下一页的数据

                    } else {

                        // app.hint("已到最后一页!", "top"); //bottom/

                        if (pullUpEl.className.match('loading')) {

                            pullUpEl.className = '';

                            pullUpEl.querySelector('.pullUpLabel').innerHTML = '加载完毕...';

                        }

                        myScroll.refresh();

                    }

                }

            }

        });

 

        setTimeout(function () { document.getElementById('wrapper').style.left = '0'; myScroll.refresh(); }, 800);

    }

}

posted @ 2013-11-26 21:39  weifb  阅读(123)  评论(0)    收藏  举报