Layui中table异步数据请求支持自定义返回数据格式
我们使用LayUI的后台管理系统框架时,会使用table.render方法与Java后端系统的controller层进行数据交互,LayUI的table.render方法处理的res返回结果有固定的数据格式,如果controller层返回的数据与LayUI不匹配时会造成LayUI无法处理后端传递过来的数据问题。
LayUI的table.render方法要求返回的数据格式如下:
使用案例:
table.render({
elem: '#test-table-toolbar'
,url:"http://localhost:8090/program-web/api/magic_change/oj/problem/page_list?userId=youcongtech"
,toolbar: '#test-table-toolbar-toolbarDemo'
,title: '程序设计题绑定'
,cols: [[
{type: 'checkbox', fixed: 'left'},
{field:'problemId', width:300, title: 'ID', sort: true}
,{field:'title', width:400, title: '题目'}
,{width:215, align:'center', fixed: 'right', toolbar: '#test-table-toolbar-barDemo'}
]]
,page: true
});
要求返回的数据格式:
{
"msg": "success