我們寫(xiě)一個(gè)函數(shù)取數(shù)據(jù):
/*將數(shù)據(jù)取出來(lái)*/function data(curr, limit) {//console.log("tot:"+totalCount)/*拿到總數(shù)據(jù)*/totalCount = testboke.data.total; //取出來(lái)的是數(shù)據(jù)總量dataLIst = testboke.data.records; // 將數(shù)據(jù)放到一個(gè)數(shù)組里面(dataLIst 還未聲明,莫著急)createTable(curr, limit, totalCount); console.log("tot:"+totalCount)}拿到數(shù)據(jù)以后怎么做,分頁(yè),是的,不是急著將數(shù)據(jù)放到表格里面,先分頁(yè),ok我們加載分頁(yè)的js(bootstrap的分頁(yè)js)
<link rel="stylesheet" /><link rel="stylesheet" /><link rel="stylesheet" /><link rel="stylesheet" /><script src="https://www.520longzhigu.com/js/bootstrap.min.js" type="text/javascript"></script><script src="https://www.520longzhigu.com/js/jquery-1.8.3-min.js" type="text/javascript"></script><script src="https://www.520longzhigu.com/js/jquery.min.js" type="text/javascript"></script><script src="https://www.520longzhigu.com/js/extendPagination.js" type="text/javascript"></script><script src="https://www.520longzhigu.com/js/layui/lay/dest/layui.all.js" type="text/javascript"></script><!--引如測(cè)試數(shù)據(jù)的js--><script src="https://www.520longzhigu.com/js/testcode.js" type="text/javascript"></script>上面的這些js,css都可以去cdn上面找到,除了testcode,在最上面,就是我們加載數(shù)據(jù)的js 。
下面就是將分頁(yè)的代碼寫(xiě)上:
var currPage = 1;var totalCount;var dataLIst = [];window.onload = function() {/*取到總條數(shù)*//*每頁(yè)顯示多少條 10條*/var limit = 10;data(currPage, limit)//console.log(totalCount)createTable(1, limit, totalCount);$('#callBackPager').extendPagination({totalCount: totalCount,limit: limit,callback: function(curr, limit, totalCount) {data(curr, limit)}});}加載以后的效果是這樣的:
這個(gè)時(shí)候就是已經(jīng)基本將數(shù)據(jù)處理好了,只是沒(méi)有將數(shù)據(jù)放進(jìn)去,最后我們將數(shù)據(jù)放進(jìn)去就可以了,(我的寫(xiě)法不建議借鑒,很多現(xiàn)成的循環(huán)畫(huà)表格的方法,我是原生的拼接字符串寫(xiě)的,不嫌麻煩的可以自己拼一下,畢竟不管是什么框架,最底層的還是這樣的實(shí)現(xiàn)原理)
/*創(chuàng)建的是一個(gè)表格,并將數(shù)據(jù)放進(jìn)去*/function createTable(currPage, limit, total) {var html = [],showNum = limit;if(total - (currPage * limit) < 0) showNum = total - ((currPage - 1) * limit);html.push(' <table class="table table-striped table-bordered templatemo-user-table" style="margin-left: 0;">');html.push(' <thead><tr><th>序號(hào)</th><th>項(xiàng)目名稱</th><th>類別</th><th>發(fā)起人</th><th>單位</th><th>詳情</th><th>操作</th></tr></thead><tbody>');for(var i = 0; i < showNum; i++) {html.push('<tr>');html.push('<td>' + dataLIst[i].id + '</td>');
以上關(guān)于本文的內(nèi)容,僅作參考!溫馨提示:如遇健康、疾病相關(guān)的問(wèn)題,請(qǐng)您及時(shí)就醫(yī)或請(qǐng)專業(yè)人士給予相關(guān)指導(dǎo)!
「愛(ài)刨根生活網(wǎng)」www.malaban59.cn小編還為您精選了以下內(nèi)容,希望對(duì)您有所幫助:- 燎原雙語(yǔ)學(xué)校圖片
- 水晶頭接法順序圖片圖解 2芯電話線水晶頭接法順序
- word多張圖片排版技巧 怎么讓word圖片自由移動(dòng)
- u盤(pán)單個(gè)文件大小限制 超過(guò)4g的文件怎么存放在u盤(pán)里面
- 快速查找字體的方法 圖片查找字體的網(wǎng)站
- fckeditor上傳圖片后出現(xiàn)白屏的原因 fckeditor上傳圖片后出現(xiàn)白屏
- 3dmax把圖片拉進(jìn)來(lái)后建模 3dmax導(dǎo)入jpg圖片建模
- pdf中的圖片導(dǎo)出的方法 pdf中的圖片如何導(dǎo)出
- c語(yǔ)言大小寫(xiě)字母轉(zhuǎn)換編程 c語(yǔ)言大小寫(xiě)轉(zhuǎn)換程序
- 什么是低碳生活圖片
