溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Layui 中table組件的作用是什么

發(fā)布時間:2021-08-12 14:16:34 來源:億速云 閱讀:172 作者:Leah 欄目:開發(fā)技術(shù)

今天就跟大家聊聊有關(guān)Layui 中table組件的作用是什么,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。

首先貼出源表格代碼:

<table class="layui-table" lay-filter="EditListTable">  <thead>    <tr>      <th lay-data="{field:'Index', width:60}">序號</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 = '';    //對于任意一個 table,按照官方的說法,有三種不同的初始化渲染方式,不多介紹,而這里使用的方式姑且看做第三種:轉(zhuǎn)換靜態(tài)表格 方式    //轉(zhuǎn)換靜態(tài)表格方式,自然首先需要有一個已經(jīng)存在的表格,然后再通過 js 方式轉(zhuǎn)化為 Layui 表格    //無論哪種方式的 Layui table 初始化自然需要配置項    //通過轉(zhuǎn)化的方式初始化 Layui table,配置項部分可以在 源table中,部分在js中,源 table 的源代碼上文已經(jīng)給出,下面給出一個示例的 js 中的配置項    var tableOptions = {        url: getListUrl, //請求地址        method: 'POST', //方式        id: 'listReload', //生成 Layui table 的標(biāo)識 id,必須提供,用于后文刷新操作,筆者該處出過問題        page: false, //是否分頁        where: { type: "all" }, //請求后端接口的條件,該處就是條件錯誤點,按照官方給出的代碼示例,原先寫成了 where: { key : { type: "all" } },結(jié)果并不是我想的那樣,如此寫,key 將是后端的一個類作為參數(shù),里面有 type 屬性,如果誤以為 key 是 Layui 提供的格式,那就大錯特錯了        response: { //定義后端 json 格式,詳細參見官方文檔            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)識id                where: {                    //key: { //該寫法上文已經(jīng)提到                        type: item.type, id: item.id                    //}                }            });        };        //表初始化        createTable();        //其他和 tree 相關(guān)的方法,其中包括 點擊 tree 項調(diào)用刷新方法    });})();

后端方法:

//本示例中,后臺代碼寫法public ActionResult GetGoalList(string type, string id){      //}//如果按照官方文檔條件項,應(yīng)該是下面的寫法public ActionResult GetGoalList(keyItem key){      //}public class keyItem{    public string id { get; set; }    public string type { get; set; }}

看完上述內(nèi)容,你們對Layui 中table組件的作用是什么有進一步的了解嗎?如果還想了解更多知識或者相關(guān)內(nèi)容,請關(guān)注億速云行業(yè)資訊頻道,感謝大家的支持。

向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI