实践是检验真理的唯一标准,只有不断的总结才会有所进步,下面总结一下我使用layui的心得和方法以及遇到的坑。
1.首先引入layui的包(从官网下载整个ui包,不要只下载layui.js和layui.css) 点击打开链接
2.html部分
<table class="layui-hide" id="test"></table>
3.js部门
layui.use(['table'], function () {
var table = layui.table;
table.render({
elem: '#test'
// , url: '/Department/ManageDeptInfo'
, method: 'POST'
, cols: [[
{ field: 'departmentName',title: '部门名称', width: 200,align:'center', sort: true }
, { field: 'departmentCode', title: '部门编号', width: 100, align: 'center', sort: true }
, { field: 'code', title: '团队类型', width: 200, align: 'center', sort: true }
, { field: 'departmentName', title: '负责人名称', width: 200, align: 'center', sort: true }
, { field: 'departmentCode', title: '负责人编号', width: 200, align: 'center', sort: true }
, { field: 'code', title: '操作', width: 200, align: 'center', sort: true }
]],
data: table_data
, page: true
});
})
(注意我的数据是提前保存到本地,所以加了data,如果是请求后台直接填写url:'链接地址')
遇到的坑:
1.数据格式要与layui的数据格式一致,否则会报错 。(数据格式点击打开链接)
2.设置样式一定要放到title的后面,否则不起作用
(后续我将总结添加编辑、新增和删除的功能)