一、前因
因后台接口获取数据成功的状态码为200,但layui的table默认的状态码为0,查阅了官方的文档没有找到相关设置,在其他地方找到了解决方法,特此记录一下方便后续查看。
二、解决方法
table.render({
elem: '#currentTableId'
, url: '/admin/get_list'
, method: 'post'
, toolbar: '#toolbarDemo'
, defaultToolbar: false //去掉右侧工具栏
, response: {
statusName: 'code' //规定数据状态的字段名称,默认:code
, statusCode: 200 //规定成功的状态码,默认:0
}
// ,cellMinWidth: 100
, cols: [[
{ type: 'checkbox' }
, { width: 100, field: 'id', title: 'APPID', sort: true, align: 'center' }
, { width: 100, field: 'name', title: '接口名称', align: 'center' }
, { width: 200, field: 'status', title: '状态', templet: '#status', sort: true, align: 'center' }
, { width: 200, title: '操作', toolbar: '#barDemo', align: 'center', fixed: 'right' }
]]
, page: true
, skin: 'line'
});