layui 方法渲染表格数据
layui.use(table, function () { const table = layui.table; //第一个实例 table.render({ elem: #demo , height: window.screen.height * 0.59 , url: /info/list , method: post , contentType: "application/json" , page: true , parseData: function (res) { //res 即为原始返回的数据 return { code: 0, msg: "", count: res.length, data: res }; } , cols: [ [ {field: infoId, title: ID, width: 80, sort: true, fixed: left} ,{field: countryId, title: 国家名称, width: 80 } , {field: universityId, title: 用户名, width: 80} , {field: directionId, title: 性别, width: 80, }
,{title: 大学英文, width: 170, templet: <div>{ {d.university.universityNameEN}}</div>}
] ] , text: {none: 无数据} }); });
注意事项
- [ [] ]要换行写
- layui 有固定的返回格式,parseData声明一下
- 如大学英文,是对象嵌套对象