layui表格解析后台返回的数据

本文介绍了一个使用layui框架实现的表格组件示例,通过HTML和JS代码展示了如何配置和渲染一个包含名称、行业、状态等字段的表格,并对服务器返回的数据进行了解析。

html代码

<table class="layui-table" id="table_user" lay-filter="table_user"> </table>

 js代码

layui.use('table', function(){
    var table = layui.table;

  table.render({
              elem: '[lay-filter="table_user"]',
              height: 300,
              url:'index.php',
              type: 'GET',
              cols:[[{ field: 'name', title: '名称' },
              { field: 'industry', title: '行业' },
               { field: 'status', title: '状态' },
                { field: 'num', title: '数量' },
                { field: 'price', title: '单价' }
          ]],
              //解析服务器端返回的数据
              parseData: function (res) {
                  /*if (res.code == 500) {
                      return false
                  }*/
                  return {
                      "code":0,
                      "msg":"",
                      "count": 1000,
                      "data": res.result
                  };
              },

          });
  });

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值