Layui 中table组件的作用是什么

发布时间:2021-08-12 14:16:34 作者:Leah
来源:亿速云 阅读:167

今天就跟大家聊聊有关Layui 中table组件的作用是什么,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

首先贴出源表格代码:

<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,按照官方的说法,有三种不同的初始化渲染方式,不多介绍,而这里使用的方式姑且看做第三种:转换静态表格 方式    //转换静态表格方式,自然首先需要有一个已经存在的表格,然后再通过 js 方式转化为 Layui 表格    //无论哪种方式的 Layui table 初始化自然需要配置项    //通过转化的方式初始化 Layui table,配置项部分可以在 源table中,部分在js中,源 table 的源代码上文已经给出,下面给出一个示例的 js 中的配置项    var tableOptions = {        url: getListUrl, //请求地址        method: 'POST', //方式        id: 'listReload', //生成 Layui table 的标识 id,必须提供,用于后文刷新操作,笔者该处出过问题        page: false, //是否分页        where: { type: "all" }, //请求后端接口的条件,该处就是条件错误点,按照官方给出的代码示例,原先写成了 where: { key : { type: "all" } },结果并不是我想的那样,如此写,key 将是后端的一个类作为参数,里面有 type 属性,如果误以为 key 是 Layui 提供的格式,那就大错特错了        response: { //定义后端 json 格式,详细参见官方文档            statusName: 'Code', //状态字段名称            statusCode: '200', //状态字段成功值            msgName: 'Message', //消息字段            countName: 'Total', //总数字段            dataName: 'Result' //数据字段        }    };    //    layui.use(['table', 'layer'], function () {//layui 模块引用,根据需要自行修改        var layer = layui.layer, table = layui.table;        //表初始化        var createTable = function () {            table.init('EditListTable', tableOptions);  // table lay-filter        };        //表刷新方法        var reloadTable = function (item) {            table.reload("listReload", { //此处是上文提到的 初始化标识id                where: {                    //key: { //该写法上文已经提到                        type: item.type, id: item.id                    //}                }            });        };        //表初始化        createTable();        //其他和 tree 相关的方法,其中包括 点击 tree 项调用刷新方法    });})();

后端方法:

//本示例中,后台代码写法public ActionResult GetGoalList(string type, string id){      //}//如果按照官方文档条件项,应该是下面的写法public ActionResult GetGoalList(keyItem key){      //}public class keyItem{    public string id { get; set; }    public string type { get; set; }}

看完上述内容,你们对Layui 中table组件的作用是什么有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注亿速云行业资讯频道,感谢大家的支持。

推荐阅读:
  1. layui中如何隐藏table的列
  2. layui框架实现分页的方法

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

layui table

上一篇:Python中Pandas数据结构的示例分析

下一篇:Mysql怎么查看连接数及状态信息

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》