layui-table渲染不出来
通过方法渲染
页面代码:
<table id="tableList" lay-filter="clublist"></table>
js代码:
layui.use('table', function () { var table = layui.table; //返回的数据必须是code:0 var tableIns = table.render({ elem: '#tableList' , height: 450 , url: '/admin/Club/Club.ashx' //数据接口 , where: { action: 'getclublistbypage' } , page: true //开启分页 , limit: 10 , cols: [[ //表头 { field: 'ID', title: 'ID', width: 80, sort: true, fixed: 'left' } , { field: 'ClubName', title: '主办方名称', width: 180 } , { field: 'ClubIntro', title: '主办方介绍', width: 180 } , { field: 'ClubLogo', title: '主办方logo', width: 180 } , { field: 'IsDel', title: '是否可用', width: 120 } , { field: 'SponsorTypeID', title: '主办方类型', width: 180 } ]] }); });
然后是接口返回的数据(使用官方的默认response)
{ code: 0, msg: "", count: 1000, data: [] }
要注意,其中code的值,官方是这么说的:
我理解的就是code反应的是你返回的数据是正确的还是错误的,假如不正确(不为0),那么页面会一直渲染不出来,这个要注意,这个问题搞了半天
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步