久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

thinkPHP5使用laypage分頁插件實(shí)現(xiàn)列表分頁功能

這篇文章主要為大家詳細(xì)介紹了thinkPHP5使用laypage分頁插件實(shí)現(xiàn)列表分頁功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

一、背景 

      在使用thinkPHP框架做項(xiàng)目的時(shí)候,經(jīng)常會(huì)遇到對(duì)列表的內(nèi)容進(jìn)行分頁。thinkPHP框架中自帶了分頁功能,但是有缺陷。這個(gè)缺陷是每次返回每頁數(shù)據(jù)給頁面時(shí)需要重新加載頁面所需要的JS、CSS等資源。如果頁面包含的JS過多、過大,會(huì)增加流量壓力。因此,我們使用laypage插件。每次使用ajax請(qǐng)求獲取每頁的數(shù)據(jù)就可以了,不需要重復(fù)加載頁面。

二、分頁流程

如下圖所示:

thinkPHP5使用laypage分頁插件實(shí)現(xiàn)列表分頁功能

流程說明:

        1) 調(diào)研App.php中的函數(shù),該函數(shù)調(diào)用fetch函數(shù)。fetch函數(shù)渲染list.html.
        2) list.html 調(diào)用獲取總頁數(shù)的函數(shù),并得到總頁數(shù)。
        3) 獲取第一頁數(shù)據(jù)。
        4)初始化laypage分頁插件。
        5)點(diǎn)擊頁碼,觸發(fā)分頁查詢。

三、實(shí)現(xiàn)分頁功能相關(guān)的代碼

1、App.php Controller的代碼

//fetch渲染頁面 
public function index() 
{ 
 return $this->fetch('list'); 
} 
 
 
 
 //根據(jù)頁面?zhèn)魅氲捻摯a查詢數(shù)據(jù) 
 public function getPage() 
 { 
   
   <span style="color:#FF0000;">// 獲取頁面?zhèn)魅氲捻摯a </span>      
   $nowpage = input("page"); 
   //每頁顯示10條數(shù)據(jù) 
   $limits = 10; 
 
   $app = new appInfo(); 
   $page_info = $app->limit(($nowpage * $limits), $limits)->select(); 
 
   // ajax 分頁輸出 
   $info = ['pageinfo'=>$page_info,'nowpage'=>$nowpage,'nowpage'=>$nowpage]; 
 
  return json($info); 
 
 
 } 
 
 
 //獲取所有頁數(shù) 
public function getAllPage(){ 
 
 try{ 
  $count = appInfo::count(); 
 
  $limits = 10; 
  // 計(jì)算總頁面 
  $allpage = ceil($count / $limits); 
 
  $info =['allpage'=>$allpage]; 
 }catch (\Exception $e){ 
  abort(500,$e->getMessage(),['result'=>TopsecGWErrer::TOPSEC_GW_ERR_NO_UNKNOWN]); 
 } 
 
 return json($info); 
} 

2、list.html中的html代碼

<div class="box-body"> 
  <table id="table1" class="table table-bordered table-striped"> 
   <thead> 
   <tr> 
    <th>應(yīng)用名稱</th> 
    <th>應(yīng)用類型</th> 
    <th>應(yīng)用圖像</th> 
    <th>創(chuàng)建日期</th> 
    <th>修改日期</th> 
    <th>操作</th> 
   </tr> 
   </thead> 
   <tbody id="table_body"></tbody> 
   <tfoot> 
 
   </tfoot> 
  </table> 
  <div id="result"></div> 
  <div class=" "> 
   <button id="add_app" type="button" class="btn btn-primary col-xs-offset-5" > 
    <span class='fa fa-tasks white'></span>丨添加應(yīng)用 
   </button> 
  </div> 
  <div id="content"> </div> 
  <div class="box-body"> 
 
   <button id="add_img" type="button" class="btn btn-primary col-xs-offset-5" > 
    <span class='fa fa-tasks white'></span>丨添加圖片 
   </button> 
  </div> 
 
  <!-- /.box-body --> 
 </div>

3、list.html中的jQuery代碼

//pageCount:總頁數(shù)。用于初始化laypage分頁控件。 
//pageIndex:初始化當(dāng)前頁。顯示第一頁。 
//currentPage:當(dāng)前頁數(shù)。 
//getPageData:獲取每頁數(shù)據(jù)的函數(shù)。 
//url:獲取每頁數(shù)據(jù)的方法的路徑。由控制器和函數(shù)名組成。 
 function jsonPage(pageCount, pageIndex,currentPage, getPageData,url) { 
  var laypageindex = laypage({ 
   cont: 'result', //容器。值支持id名、原生dom對(duì)象,jquery對(duì)象。 
   skin: '#3c8dbc', 
   pages: pageCount, //通過后臺(tái)拿到的總頁數(shù) 
   curr: pageIndex, //初始化當(dāng)前頁 
   prev: '上一頁', //若不顯示,設(shè)置false即可 
   next: '下一頁', //若不顯示,設(shè)置false即可 
   skip: true, //是否開啟跳頁 
   jump: function (obj, first) { //觸發(fā)分頁后的回調(diào) 
    //getPageData(1); 
    if (!first) { //點(diǎn)擊跳頁觸發(fā)函數(shù)自身,并傳遞當(dāng)前頁:obj.curr 
     getPageData(url,obj.curr); 
     currentPage = obj.curr; 
    } 
   } 
  }); 
 } 
 
 
/url:獲取總頁數(shù)據(jù)的方法的路徑。由控制器和函數(shù)名組成。  
 function getAllpage(url){ 
 
  var tmp ; 
  $.ajax({ 
   type: "GET", 
   dataType: "json", 
   async: false, 
   url: PUBLIC_BASE+url, 
   success: function(json) { 
    var data = eval(json); 
    tmp=data.allpage; 
   }, 
   error: function(json) { 
 
   } 
 
  }); 
  return tmp; 
 
 } 
 
 //data:每頁的數(shù)據(jù)。由JSON對(duì)象組成。 
 function instantiation(data) { 
  //begin $.each 
  $.each(data.pageinfo, function (index, item) { 
   $("#table_body").append($('<tr class="table_tr"/>') 
    .append($("<td/>").html(item.name)) 
    .append($("<td/>").html(item.desc)) 
    .append($("<td/>").html("<img src='"+item.appImg+"' />")) 
    .append($("<td/>").html(item.create_time)) 
    .append($("<td/>").html(item.update_time)) 
    .append( 
     $("<td />") 
      .append($("<a class='yellow' id='view"+item.id+"'><i class='fa fa-eye fa-fw'></i>查看丨 </a>")) 
      .append($("<a class='green' id='edit"+item.id+"'><i class='fa fa-edit fa-fw'></i>編輯丨 </a>")) 
      .append($("<a class='red' id='delete"+item.id+"'><i class='fa fa-remove fa-fw'></i>刪除丨 </a>")) 
      .append($("<a class='blue' id='forbid" + item.id + "'><i class='fa fa-ban fa-fw'></i>禁用</a>")) 
 
    ) 
 
   ); 
 
   $("#view"+item.id).click(function() { 
    fillMainContent("/application/application?model=view&id="+item.id); 
   }) 
 
   $("#edit"+item.id).click(function() { 
    fillMainContent("/application/application?model=edit&id="+item.id); 
   }) 
 
   $("#delete"+item.id).click(function() { 
 
    deleteApp(item.id); 
    alert("刪除成功"); 
 
   }) 
 
   $("#forbid"+item.id).click(function() { 
    deleteApp(item.id); 
    alert("刪除成功"); 
    getPageData(currentPage); 
   }) 
 
  }); 
  //end $.each 
   
 }  
 //獲取每頁的數(shù)據(jù)。curr:頁碼 ,curl:獲取數(shù)據(jù)的路徑。 
 function getPageData(url,curr) { 
  curr = curr-1; 
  $.ajax({ 
 
   type: "GET", 
   dataType: "json", 
   data: {page:curr}, 
   url: PUBLIC_BASE+url, 
   success: function(json) { 
    $('#table_body').empty(); 
    var data = eval(json); 
    console.log(data); 
 
    instantiation(data); 
   }, 
 
   error: function(json) { 
 
    var data = eval(json); 
    console.log(data); 
 
   } 
 
  }); 
 
 } 
 
 <span style="color:#FF0000;">//調(diào)用函數(shù)實(shí)現(xiàn)分頁</span> 
//獲取總頁數(shù),用于初始化分頁控件總頁數(shù) 
 pageCount= getAllpage("/application/getAllPage"); 
 //獲取第一頁數(shù)據(jù) 
 getPageData("/application/getpage",1); 
 //初始化分頁控件并分頁 
 jsonPage(pageCount,pageIndex,currentPage,getPageData,"/application/getpage"); 

四、參考資源

http://laypage.layui.com/

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持。

【網(wǎng)站聲明】本站除付費(fèi)源碼經(jīng)過測(cè)試外,其他素材未做測(cè)試,不保證完整性,網(wǎng)站上部分源碼僅限學(xué)習(xí)交流,請(qǐng)勿用于商業(yè)用途。如損害你的權(quán)益請(qǐng)聯(lián)系客服QQ:2655101040 給予處理,謝謝支持。

相關(guān)文檔推薦

這篇文章主要介紹了thinkphp5.0驗(yàn)證類的簡(jiǎn)單有效的使用方法,一起學(xué)習(xí)下。
本文主要講了thinkphp5.0版本中自定義驗(yàn)證規(guī)則的使用方法和一些注意事項(xiàng)。
這篇文章主要介紹了Thinkphp5+PHPExcel實(shí)現(xiàn)批量上傳表格數(shù)據(jù)功能,需要的朋友可以參考下
本文是thinkphp開發(fā)系列文章中關(guān)于使用七牛云儲(chǔ)存的方法和具體實(shí)例,非常的簡(jiǎn)單,有需要的小伙伴可以參考下
本篇文章主要介紹了淺談thinkphp5 instance 的簡(jiǎn)單實(shí)現(xiàn),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
今天有個(gè)朋友詢問tp5支持pathinfo的nginx配置怎么寫的問題,所以想著自己總結(jié)分享下,下面這篇文章主要給大家介紹了關(guān)于在Nginx下ThinkPHP5的配置方法,需要的朋友可以參考借鑒,下面話
主站蜘蛛池模板: 欧美在线天堂 | 欧美成人第一页 | 在线观看黄色 | 99精品视频免费观看 | 亚洲 中文 欧美 日韩 在线观看 | 正在播放国产精品 | 一区二区三区欧美 | 一级黄色毛片 | 亚洲一区二区在线视频 | 四虎在线观看 | 九九热视频这里只有精品 | 欧美日韩亚洲一区二区 | 中文字幕在线观 | 国产大学生情侣呻吟视频 | 亚洲欧美中文日韩在线v日本 | 国产永久免费 | 日韩三级视频 | 777777777亚洲妇女 | 337p日本欧洲亚洲大胆鲁鲁 | 久久伊 | 福利一区二区在线 | 色综合区 | 在线观看三级av | 久久91| 91干b| 日韩精品一区二区三区四区 | 精品一区国产 | 久久久亚洲 | 亚洲精品成人在线 | 欧美一级三级 | 国产午夜av片 | 久久久青草婷婷精品综合日韩 | 亚洲一二三区在线观看 | 成年人在线视频 | 午夜一区二区三区 | 亚洲高清在线观看 | 成人在线精品视频 | 精品一区二区三区不卡 | 美女一区二区在线观看 | 毛片在线免费播放 | 午夜爽爽男女免费观看hd |