关于LayUIAdminPro使用table.render时,报错成功码应为0的解决办法(LayUI踩坑篇二)

文中的LayUIAdminPro版本为v2020.4.1。使用的软件是IDEA,你问我为什么不用vsCode?为了偷懒,就使用IDEA。

在使用当我们的成功码和LayUI的成功码不一致时,会出现下图这种错误。
在这里插入图片描述
下面是一个table.render请求,这样去请求的话,会报上图这种错误。

table.render({
    elem: '#LAY-stream-user-manage',
    url: 'http://localhost:8001/api/user/find',
    method: "post",
    contentType: "application/json;charset=UTF-8",
    dataType: "json",
    where: {
		'type': 'user'
	},
    cols: [[
        {type: 'checkbox', fixed: 'left'},
        {field: 'id', title: 'User_id', templet: '#LAY-user-id'},
        {field: 'nickname', title: 'User_name'},
        {field: 'email', title: 'User_email'},
        {field: 'loginTime', title: 'User_last_login_at', sort: true},
        {field: 'enabled', title: 'User_status', templet: '#LAY-user-status'},
        {title: 'Action', align: 'center', fixed: 'right', toolbar: '#table-content-list'}
    ]],
    autoSort: false,
    skin: "line",
    page: {limit: 10, sort: 'id', desc: false, curr: 1, groups: 3},
    limit: 10,
    limits: [10, 15, 20, 25, 30],
    text: {none: '查无数据'},
});

解决办法是在table.render中加上parseData属性,在函数中解析状态码。

table.render({
    elem: '#LAY-stream-user-manage',
    url: 'http://localhost:8001/api/user/find',
    method: "post",
    contentType: "application/json;charset=UTF-8",
    dataType: "json",
    where: {
		'type': 'user'
	},
    cols: [[
        {type: 'checkbox', fixed: 'left'},
        {field: 'id', title: 'User_id', templet: '#LAY-user-id'},
        {field: 'nickname', title: 'User_name'},
        {field: 'email', title: 'User_email'},
        {field: 'loginTime', title: 'User_last_login_at', sort: true},
        {field: 'enabled', title: 'User_status', templet: '#LAY-user-status'},
        {title: 'Action', align: 'center', fixed: 'right', toolbar: '#table-content-list'}
    ]],
    autoSort: false,
    skin: "line",
    page: {limit: 10, sort: 'id', desc: false, curr: 1, groups: 3},
    limit: 10,
    limits: [10, 15, 20, 25, 30],
    text: {none: '查无数据'},
    parseData: function (res) { //res 即为原始返回的数据
            // 解析响应结果
            return {
                "code": 0 //解析接口状态
            }
        }
});
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值