欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Layui table 組件的使用之初始化加載數(shù)據(jù)、數(shù)據(jù)刷新表格、傳參數(shù)

 更新時(shí)間:2017年09月11日 11:03:47   作者:LoveLong  
這篇文章主要介紹了Layui table 組件的使用之初始化加載數(shù)據(jù)、數(shù)據(jù)刷新表格、傳參數(shù)的實(shí)現(xiàn)代碼,需要的朋友可以參考下

背景

筆者之前一直使用 bootstrap table ,因?yàn)楫?dāng)前項(xiàng)目中主要使用 Layui 框架,于是也就隨了 Layui table ,只是在使用的時(shí)候出現(xiàn)了一些問題,當(dāng)然也是怪自己不熟悉的鍋吧!

出現(xiàn)的問題:

1、使用 Layui 官方提供的 【轉(zhuǎn)換靜態(tài)表格】 方式初始化加載時(shí)報(bào) id 找不到的錯(cuò)誤(自己的鍋)

2、傳遞參數(shù)問題(姑且算是 Layui 官方的鍋)

筆者使用的 table 加載刷新方案

有一個(gè)頁面,左側(cè)是一個(gè) tree,右側(cè)是一個(gè) table,默認(rèn) table 加載全數(shù)據(jù),當(dāng)點(diǎn)擊 tree 節(jié)點(diǎn)時(shí),table 進(jìn)行篩選,很簡單的需求吧!

 

這里我們不談 tree 的使用,將僅僅貼出 table 的相關(guān)方法!

首先貼出源表格代碼:

<table class="layui-table" lay-filter="EditListTable">
 <thead>
 <tr>
  <th lay-data="{field:'Index', width:60}">序號(hào)</th>
  <th lay-data="{field:'UserId', width:80}">銷售ID</th>
  <th lay-data="{field:'UserName', width:80}">姓名</th>
  <th lay-data="{field:'Year', width:70}">年份</th>
  <th lay-data="{field:'M01', width:80}">一月</th>
  <th lay-data="{field:'M02', width:80}">二月</th>       
  <th lay-data="{field:'YearValue', width:80, fixed: 'right'}">年度</th>
  <th lay-data="{width:100, align:'center', toolbar: '#barDemo1', fixed: 'right'}">操作</th>
 </tr>
 </thead>
</table>
<script type="text/html" id="barDemo1">
 <a class="layui-btn layui-btn-mini" lay-event="edit">編輯</a>
</script>

直接在代碼中通過注釋講解:

(function () {
 //加載列表的后端 url
 var getListUrl = '';
 //對(duì)于任意一個(gè) table,按照官方的說法,有三種不同的初始化渲染方式,不多介紹,而這里使用的方式姑且看做第三種:轉(zhuǎn)換靜態(tài)表格 方式
 //轉(zhuǎn)換靜態(tài)表格方式,自然首先需要有一個(gè)已經(jīng)存在的表格,然后再通過 js 方式轉(zhuǎn)化為 Layui 表格
 //無論哪種方式的 Layui table 初始化自然需要配置項(xiàng)
 //通過轉(zhuǎn)化的方式初始化 Layui table,配置項(xiàng)部分可以在 源table中,部分在js中,源 table 的源代碼上文已經(jīng)給出,下面給出一個(gè)示例的 js 中的配置項(xiàng)
 var tableOptions = {
  url: getListUrl, //請(qǐng)求地址
  method: 'POST', //方式
  id: 'listReload', //生成 Layui table 的標(biāo)識(shí) id,必須提供,用于后文刷新操作,筆者該處出過問題
  page: false, //是否分頁
  where: { type: "all" }, //請(qǐng)求后端接口的條件,該處就是條件錯(cuò)誤點(diǎn),按照官方給出的代碼示例,原先寫成了 where: { key : { type: "all" } },結(jié)果并不是我想的那樣,如此寫,key 將是后端的一個(gè)類作為參數(shù),里面有 type 屬性,如果誤以為 key 是 Layui 提供的格式,那就大錯(cuò)特錯(cuò)了
  response: { //定義后端 json 格式,詳細(xì)參見官方文檔
   statusName: 'Code', //狀態(tài)字段名稱
   statusCode: '200', //狀態(tài)字段成功值
   msgName: 'Message', //消息字段
   countName: 'Total', //總數(shù)字段
   dataName: 'Result' //數(shù)據(jù)字段
  }
 };
 //
 layui.use(['table', 'layer'], function () {//layui 模塊引用,根據(jù)需要自行修改
  var layer = layui.layer, table = layui.table;
  //表初始化
  var createTable = function () {
   table.init('EditListTable', tableOptions);// table lay-filter
  };
  //表刷新方法
  var reloadTable = function (item) {
   table.reload("listReload", { //此處是上文提到的 初始化標(biāo)識(shí)id
    where: {
     //key: { //該寫法上文已經(jīng)提到
      type: item.type, id: item.id
     //}
    }
   });
  };
  //表初始化
  createTable();
  //其他和 tree 相關(guān)的方法,其中包括 點(diǎn)擊 tree 項(xiàng)調(diào)用刷新方法
 });
})();

后端方法:

//本示例中,后臺(tái)代碼寫法
public ActionResult GetGoalList(string type, string id)
{
  //
}

//如果按照官方文檔條件項(xiàng),應(yīng)該是下面的寫法

public ActionResult GetGoalList(keyItem key)
{
  //
}
public class keyItem
{
 public string id { get; set; }
 public string type { get; set; }
}

總結(jié)

以上所述是小編給大家介紹的Layui table 組件的使用之初始化加載數(shù)據(jù)、數(shù)據(jù)刷新表格、傳參數(shù),希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論