OData 協議 asp.net Mvc WebAPI分頁筆記

來源:互聯網
上載者:User

標籤:function   asp.net   success   window   count   

// 針對 OData協議的Mvc WebAPI 2.2 分頁外掛程式    ; (function ($, window) {        var tbPQ = function () {        };        // get the length from ‘urlAndParamter‘        function getCount(urlAndParamter, ok_handler) {            $.ajax(urlAndParamter, {                type: "get",                async: true,                dataType: ‘json‘,                crossDomain: true,                success: function (count) {                    if (!isNaN(count)) {                        if (typeof ok_handler === ‘function‘) {                            ok_handler.call(count, count);                        }                    } else {                        throw new Error("can‘t convert to number ");                    }                },                error: function (XMLHttpRequest, error) {                    throw new Error("can‘t get the data count from the url ");                }            });        };        // get the data list from ‘urlAndParamter‘        function getData(urlAndParamter, page, psize, total, ok_handler) {            // compute and set the $skip value            var $skip = (page - 1) * psize;            if ($skip > total) $skip = 0;            if (urlAndParamter.indexOf(‘?‘) < 0) {                urlAndParamter = urlAndParamter + "?l=p";            }            urlAndParamter = urlAndParamter + "&$skip=" + $skip + "&$top=" + psize;            $.ajax(urlAndParamter, {                type: "get",                async: true,                dataType: ‘json‘,                crossDomain: true,                success: function (data) {                    if (typeof ok_handler === ‘function‘) {                        // data.total -> 記錄總數                        // data.skip  -> 跳過條數(一般計算方式為:單頁顯示數*上一頁的頁碼值)                        // data.top   -> 單頁條數(單頁資料最多顯示的資料)                        // data.page  -> 當前頁碼                        // data.mpage -> 最大頁碼                        // data.list  -> 資料列表                        // build the result for return                        var result = {                            total: total,                            skip: $skip,                            top: psize,                            page: page,                            mpage: parseInt(Math.floor(total / psize)),                            list: data                        };                        ok_handler.call(result, result);                    }                },                error: function (XMLHttpRequest, error) {                    // alert(error);                    throw new Error("can‘t get the data count from the url ");                }            });        }        // tbPQ Plugin        tbPQ.fn = tbPQ.prototype = {            constructor: tbPQ,            init: function () {                return new tbPQ().constructor;            },            buildPage: function (psize, total) {            },            getPagedData: function (durlAndParam, qurlAndParam, page, psize, ok) {                getCount(qurlAndParam, function (count) {                    getData(durlAndParam, page, psize, count, ok);                })            },            getPagedData1: function (url, page, psize, ok) {                tbPQ.fn.getPagedData(url, url + "/?qc=1", page, psize, ok);            },        };        tbPQ.fn.init.prototype = tbPQ.prototype;        window.TbPQ = tbPQ.fn.init();    })(jQuery, window);    //TbPQ.fn.getPagedData1("http://localhost:43402/api/loginlog", 1, 20, function (data) {    //    // data.total -> 記錄總數    //    // data.skip  -> 跳過條數(一般計算方式為:單頁顯示數*上一頁的頁碼值)    //    // data.top   -> 單頁條數(單頁資料最多顯示的資料)    //    // data.page  -> 當前頁碼    //    // data.mpage -> 最大頁碼    //    // data.list  -> 資料列表    //    alert(data.list.length);    //});


本文出自 “傻帽” 部落格,請務必保留此出處http://hotboy.blog.51cto.com/8826994/1650505

OData 協議 asp.net Mvc WebAPI分頁筆記

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.