javascript - 从后台取回的json数组,如何用easyui的datagrid显示出来?
伊谢尔伦
伊谢尔伦 2017-04-11 11:17:21
[JavaScript讨论组]
点击button调用getAll方法从数据库取数据
jsp代码:

<input type="text" class="txt">
<button onclick="getAll()">查询</button><br/>
<table id="dg-order" ></table>

js代码:
     function getAll(){
            var text = $('.txt').val();
            $.ajax({
              url:basePath+"list/all",
              data:{
                 userid:text,
                 },
              success:function(result){
              $('#dg-order').datagrid("loadDate",result);
              }
           });
        };

result为返回的json字符串[{"address":"将军路","orderItemList":[{"id":180,"num":2,"price":40.0}],"status":0,"userId":16}]

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

全部回复(1)
巴扎黑

之前做了个项目后台是easyui,做了分页每页20条数据:

页面引入easyui库,table加上class="easyui-datagrid"

<table id="dg" class="easyui-datagrid" title="用户信息" style="height:500px" data-options="
            rownumbers:true,
            singleSelect:true,
            autoRowHeight:true,
            pagination:true,
            pageSize:20,
            url:'<%=request.getContextPath()%>/admin/user/list-by-page.jspx',
            method:'get',
            toolbar:'#tb'">
    <thead>
        <tr>
            <th data-options="field:'id',width:50">ID</th>
            <th data-options="field:'nickname',width:250">手机号码</th>
            <th data-options="field:'equipIds',width:300">绑定装备</th>
            <th data-options="field:'currentequiment',width:150">当前装备</th>
            <th data-options="field:'createtime',width:150">注册时间</th>
        </tr>
    </thead>
</table>

搜索加载数据

我这里搜索条件是:用户ID

$('#dg').datagrid('load',{
    accountId: $('#accountId').val(),
});

服务器返回数据格式

后台api数据应该按照这种格式返回:

{
    "total": 15, 
    "rows": [
        {
            "createtime": "2016-07-06 16:26:04", 
            "id": 7, 
            "createTime": 1467793564, 
            "nickname": "13433333333(Jan)", 
            "updateTime": 1470795733, 
            "currentequiment": 0, 
            "equipIds": ""
        }, 
        ...
    ]
}
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号