通過方法渲染
頁面代碼:
<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),那么頁面會一直渲染不出來,這個要注意,這個問題搞了半天