方法渲染table数据请求异常

已采纳
41 543
Jay337
Jay337 17天前
悬赏:20飞吻
{code:0,msg:"",count:11,data:[{"px":1,"id":14,"user_name":"周冬雨","account":"zdy","password":"21232f297a57a5a743894a0e4a801fc3","sex":"女","role_name":"总监","charger":"超级管理员","state":0},{"px":2,"id":15,"user_name":"何润东","account":"hrd","password":"21232f297a57a5a743894a0e4a801fc3","sex":"男","role_name":"经理","charger":"周冬雨","state":0},{"px":3,"id":16,"user_name":"赵丽颖","account":"zly","password":"21232f297a57a5a743894a0e4a801fc3","sex":"女","role_name":"经理","charger":"周冬雨","state":0},{"px":4,"id":17,"user_name":"桃谷","account":"tghlx","password":"21232f297a57a5a743894a0e4a801fc3","sex":"女","role_name":"经理","charger":"周冬雨","state":0},{"px":5,"id":18,"user_name":"克拉克","account":"klk","password":"21232f297a57a5a743894a0e4a801fc3","sex":"男","role_name":"运维","charger":"桃谷","state":0},{"px":6,"id":19,"user_name":"蝙蝠侠","account":"bfx","password":"21232f297a57a5a743894a0e4a801fc3","sex":"男","role_name":"运维","charger":"桃谷","state":0},{"px":7,"id":20,"user_name":"钢铁侠","account":"gtx","password":"21232f297a57a5a743894a0e4a801fc3","sex":"男","role_name":"运维","charger":"桃谷","state":0},{"px":8,"id":21,"user_name":"王尼玛","account":"wnm","password":"21232f297a57a5a743894a0e4a801fc3","sex":"男","role_name":"运维","charger":"赵丽颖","state":0},{"px":9,"id":22,"user_name":"神奇女侠","account":"sqnx","password":"21232f297a57a5a743894a0e4a801fc3","sex":"女","role_name":"运维","charger":"何润东","state":0},{"px":10,"id":23,"user_name":"奥巴马","account":"abm","password":"21232f297a57a5a743894a0e4a801fc3","sex":"男","role_name":"运维","charger":"桃谷","state":0}]}
回帖
  • 那应该是你传过去的数据是有问题的,或者是没有读取到数据
    0 回复
  • [挖鼻] 异常呢
    0 回复
  • Jay337
    17天前
    @随❤所☆预 兄弟求指点,问题出在哪呢
    0 回复
  • - -我学java后端的,用法不一样,你后端数据返回给前端了吗
    0 回复
  • Jay337
    17天前
    @随❤所☆预 返回了啊
    0 回复
  • Jay337
    17天前
    0 回复
  • @Jay337 那应该直接字段名就会显示在table里面了
    0 回复
  • 先检查 url地址解析是否正确,
    数据没毛病[思考]
    0 回复
  • Jay337
    17天前
    @炸毛的小老虎 C#后台,调试都进去了,地址是没问题
    0 回复
  • @随❤所☆预 [汗] 不同语言无法为你解决
    0 回复
  • @Jay337 count有11条,但是你的数据只有10条
    0 回复
  • Jay337
    17天前
    0 回复
  • @Jay337 [耶] 结贴
    0 回复
  • count总页数不影响的吧
    0 回复
  • Jay337
    17天前
    @随❤所☆预 count是总数据条数吧
    0 回复
  • Jay337
    17天前
    @炸毛的小老虎 不可能的,我和这问题不死不休
    0 回复
  • [汗] 。。。。,你解决了
    0 回复
  • Jay337
    17天前
    @随❤所☆预 没,蛋疼啊
    0 回复
  • [吃惊] 到底是解决没。条数和data条数不对应,从你的截图没看出其他问题了
    0 回复
  • @Jay337 你用jq异步请求下输出下是否返回数据
    0 回复
  • Jay337
    17天前
    代码都贴上吧,请大佬们审查
        <table id="UserTable">
    </table>
    <script src="../Script/layui/layui.js" charset="utf-8"></script>
    <script>
    layui.use('table', function () {
    var table = layui.table;
    table.render({
    elem: '#UserTable',
    url: 'AjaxUser.aspx',
    where: { method: 'GetUser' },
    height: 315,
    width: 'auto',
    page: true,
    limits: [10, 20, 30],
    limit: 10,
    id: 'id',
    cols: [[
    { checkbox: true },
    { field: 'id', title: 'ID', width: 80 },
    { field: 'user_name', title: '用户名', width: 80 },
    { field: 'sex', title: '性别', width: 80 },
    { field: 'account', title: '账号', width: 80 },
    { field: 'password', title: '密码', width: 80 },
    { field: 'role_name', title: '角色', width: 80 },
    { field: 'charger', title: '主管', width: 80 },
    { field: 'state', title: '状态', width: 80 }
    ]],
    done: function (res, curr, count) {
    //如果是异步请求数据方式,res即为你接口返回的信息。
    //如果是直接赋值的方式,res即为:{data: [], count: 99} data为当前页数据、count为数据总长度
    console.log(res);

    //得到当前页码
    console.log(curr);

    //得到数据总量
    console.log(count);
    }
    });
    });
    </script>
    0 回复
  • Jay337
    17天前
    后台
            #region 获取用户列表
    public void GetUser()
    {
    string username = Request["key"] ?? "".Trim();
    int state = Request["state"] == null ? 0 : int.Parse(Request["state"].ToString());
    int pageIndex = Convert.ToInt32(Request["page"]);
    int pageSize = Convert.ToInt32(Request["limit"]);
    int role_id = int.Parse(Session["userRole"].ToString());
    int user_id = int.Parse(Session["userId"].ToString());
    DataSet ds = BLL.User.GetUser(role_id, user_id, username, pageIndex, pageSize, state);
    string a = HelpFunction.LayEncode(ds.Tables[0], int.Parse(ds.Tables[1].Rows[0][0].ToString()));
    Response.Write(LayEncode(ds.Tables[0], int.Parse(ds.Tables[1].Rows[0][0].ToString())));

    }
    public static string LayEncode(object o, int total)
    {
    return "{count:" + total + ",data:" + JsonConvert.SerializeObject(o) + "}";
    }
    #endregion
    0 回复
  • Jay337
    17天前
    @炸毛的小老虎 哦~这也许是个问题,我看看
    0 回复
  • Jay337
    17天前
    @炸毛的小老虎 不是条数的问题
    0 回复
  • @Jay337 where 和method 哪里是不是有错- -
    0 回复
  • 你可以先直接用data赋值看看 能不能显示http://www.layui.com/doc/modules/table.html#data
    0 回复
  • Jay337
    17天前
    @随❤所☆预 没,这个只是我通过这个方法名跳转到该方法,后台也执行正确了
    0 回复
  • @Jay337 我是用异步请求回调后再进行表格的渲染,我没有用url的,是用data
    0 回复
  • Jay337
    17天前
    0 回复
  • Jay337
    17天前
    @随❤所☆预 哦,这样啊
    0 回复
近期热议
layui 2.1.5 发布,局部细节优化 68
预告一下,下一个版本 table 模块会大幅增强 49
开放 layui 官方交流二群 28
table 里面的删除按钮怎么操作 24
经多人举报,某 layui 千人群存在管理员恶意误导行为 23
form事件提交以后,后台返回的json怎么获取? 22
数据表格 自定义响应体 无反应 22
layui图标显示问题 21
数据表格的使用问题!!急求大佬帮忙解决 21
java后台快速开发框架automain发布,前端部分支持且仅支持layui 19
layui

微信扫码关注 layui 公众号