Easyui TreeGrid树形表格返回json数据不显示问题

老规矩还是先上图看效果:

这是正确的效果图差不多花了两天的时间去研究这个TreeGrid树形表格,错误原因就是 json 问题,先看返回的json数据:

{
    "menu": [{
        "m_id": 1,
        "m_name": "工作平台",
        "m_code": "001",
        "m_childrenId": 0,
        "m_icon": "fa fa-television fa-2x",
        "m_url": "ww.baidu.com",
        "m_time": 1527557191000,
        "m_text": "",
        "m_sort": 0,
        "m_level": 0,
        "m_statu": 0,
        "menus": [{
            "m_id": 32,
            "m_name": "客户管理",
            "m_code": "",
            "m_childrenId": 1,
            "m_icon": "icon-group group",
            "m_url": "暂时空",
            "m_time": 1527748186000,
            "m_text": "客户管理",
            "m_sort": 1,
            "m_level": 0,
            "m_statu": 0,
            "menus": [{
                "m_id": 36,
                "m_name": "测试一",
                "m_code": "",
                "m_childrenId": 32,
                "m_icon": "icon-cog",
                "m_url": "",
                "m_time": null,
                "m_text": "",
                "m_sort": 0,
                "m_level": 0,
                "m_statu": 0,
                "menus": []
            }, {
                "m_id": 37,
                "m_name": "测试第二",
                "m_code": "",
                "m_childrenId": 32,
                "m_icon": "icon-cog",
                "m_url": "",
                "m_time": null,
                "m_text": "",
                "m_sort": 0,
                "m_level": 0,
                "m_statu": 0,
                "menus": []
            }]
        }]
    }, {
        "m_id": 2,
        "m_name": "工具",
        "m_code": "002",
        "m_childrenId": 0,
        "m_icon": "fa fa-cubes fa-2x",
        "m_url": "ww.baidu.com",
        "m_time": 1527557191000,
        "m_text": "",
        "m_sort": 0,
        "m_level": 0,
        "m_statu": 0,
        "menus": [{
            "m_id": 33,
            "m_name": "工作日志",
            "m_code": "",
            "m_childrenId": 2,
            "m_icon": "icon-building",
            "m_url": "暂空",
            "m_time": 1527748268000,
            "m_text": "工作日志描述",
            "m_sort": 2,
            "m_level": 0,
            "m_statu": 0,
            "menus": []
        }]
    }, {
        "m_id": 3,
        "m_name": "数据统计",
        "m_code": "003",
        "m_childrenId": 0,
        "m_icon": "fa fa-bar-chart fa-2x",
        "m_url": "ww.baidu.com",
        "m_time": 1527557191000,
        "m_text": "",
        "m_sort": 0,
        "m_level": 0,
        "m_statu": 0,
        "menus": [{
            "m_id": 34,
            "m_name": "客户统计",
            "m_code": "",
            "m_childrenId": 3,
            "m_icon": "icon-chart-pie",
            "m_url": "暂空",
            "m_time": 1527748323000,
            "m_text": "客户统计",
            "m_sort": 3,
            "m_level": 0,
            "m_statu": 0,
            "menus": []
        }]
    }, {
        "m_id": 4,
        "m_name": "系统管理",
        "m_code": "004",
        "m_childrenId": 0,
        "m_icon": "fa fa-cog fa-2x",
        "m_url": "ww.baidu.com",
        "m_time": 1527557191000,
        "m_text": "",
        "m_sort": 0,
        "m_level": 0,
        "m_statu": 0,
        "menus": [{
            "m_id": 35,
            "m_name": "系统管理",
            "m_code": "",
            "m_childrenId": 4,
            "m_icon": "icon-cog",
            "m_url": "暂空",
            "m_time": 1527748369000,
            "m_text": "系统管理描述",
            "m_sort": 4,
            "m_level": 0,
            "m_statu": 0,
            "menus": []
        }]
    }, {
        "m_id": 5,
        "m_name": "更多",
        "m_code": "005",
        "m_childrenId": 0,
        "m_icon": "fa fa-list fa-2x",
        "m_url": "ww.baidu.com",
        "m_time": 1527557192000,
        "m_text": "",
        "m_sort": 0,
        "m_level": 0,
        "m_statu": 0,
        "menus": []
    }]

}

在这讲解一下easyui TreeGrid的返回json格式的要求(必须严格按照官方的json格式):

(1)基本json数据格式:

[
    {
        "m_id": 1,
        "m_name": "工作平台",
        "m_code": "001",
        "m_childrenId": 0,
        "m_icon": "fa fa-television fa-2x",
        "m_url": "ww.baidu.com",
        "m_time": 1527557191000,
        "m_text": "",
        "m_sort": 0,
        "m_level": 0,
        "m_statu": 0,
        "children": [
            {
                "m_id": 32,
                "m_name": "客户管理",
                "m_code": "",
                "m_childrenId": 1,
                "m_icon": "icon-group group",
                "m_url": "暂时空",
                "m_time": 1527748186000,
                "m_text": "客户管理",
                "m_sort": 1,
                "m_level": 0,
                "m_statu": 0,
                "children": [
                    {
                        "m_id": 36,
                        "m_name": "测试一",
                        "m_code": "",
                        "m_childrenId": 32,
                        "m_icon": "icon-cog",
                        "m_url": "",
                        "m_time": null,
                        "m_text": "",
                        "m_sort": 0,
                        "m_level": 0,
                        "m_statu": 0,
                        "children": [
                            
                        ]
                    },
                    {
                        "m_id": 37,
                        "m_name": "测试第二",
                        "m_code": "",
                        "m_childrenId": 32,
                        "m_icon": "icon-cog",
                        "m_url": "",
                        "m_time": null,
                        "m_text": "",
                        "m_sort": 0,
                        "m_level": 0,
                        "m_statu": 0,
                        "children": [
                            
                        ]
                    }
                ]
            }
        ]
    },
    {
        "m_id": 2,
        "m_name": "工具",
        "m_code": "002",
        "m_childrenId": 0,
        "m_icon": "fa fa-cubes fa-2x",
        "m_url": "ww.baidu.com",
        "m_time": 1527557191000,
        "m_text": "",
        "m_sort": 0,
        "m_level": 0,
        "m_statu": 0,
        "children": [
            {
                "m_id": 33,
                "m_name": "工作日志",
                "m_code": "",
                "m_childrenId": 2,
                "m_icon": "icon-building",
                "m_url": "暂空",
                "m_time": 1527748268000,
                "m_text": "工作日志描述",
                "m_sort": 2,
                "m_level": 0,
                "m_statu": 0,
                "children": [
                    
                ]
            }
        ]
    },
    {
        "m_id": 3,
        "m_name": "数据统计",
        "m_code": "003",
        "m_childrenId": 0,
        "m_icon": "fa fa-bar-chart fa-2x",
        "m_url": "ww.baidu.com",
        "m_time": 1527557191000,
        "m_text": "",
        "m_sort": 0,
        "m_level": 0,
        "m_statu": 0,
        "children": [
            {
                "m_id": 34,
                "m_name": "客户统计",
                "m_code": "",
                "m_childrenId": 3,
                "m_icon": "icon-chart-pie",
                "m_url": "暂空",
                "m_time": 1527748323000,
                "m_text": "客户统计",
                "m_sort": 3,
                "m_level": 0,
                "m_statu": 0,
                "children": [
                    
                ]
            }
        ]
    },
    {
        "m_id": 4,
        "m_name": "系统管理",
        "m_code": "004",
        "m_childrenId": 0,
        "m_icon": "fa fa-cog fa-2x",
        "m_url": "ww.baidu.com",
        "m_time": 1527557191000,
        "m_text": "",
        "m_sort": 0,
        "m_level": 0,
        "m_statu": 0,
        "children": [
            {
                "m_id": 35,
                "m_name": "系统管理",
                "m_code": "",
                "m_childrenId": 4,
                "m_icon": "icon-cog",
                "m_url": "暂空",
                "m_time": 1527748369000,
                "m_text": "系统管理描述",
                "m_sort": 4,
                "m_level": 0,
                "m_statu": 0,
                "children": [
                    
                ]
            }
        ]
    },
    {
        "m_id": 5,
        "m_name": "更多",
        "m_code": "005",
        "m_childrenId": 0,
        "m_icon": "fa fa-list fa-2x",
        "m_url": "ww.baidu.com",
        "m_time": 1527557192000,
        "m_text": "",
        "m_sort": 0,
        "m_level": 0,
        "m_statu": 0,
        "children": [
            
        ]
    }

]


(2)带rows的数据格式(rows必须一致不能少擅自修改)

{ "rows" :[
    {
        "m_id": 1,
        "m_name": "工作平台",
        "m_code": "001",
        "m_childrenId": 0,
        "m_icon": "fa fa-television fa-2x",
        "m_url": "ww.baidu.com",
        "m_time": 1527557191000,
        "m_text": "",
        "m_sort": 0,
        "m_level": 0,
        "m_statu": 0,
        "children": [
            {
                "m_id": 32,
                "m_name": "客户管理",
                "m_code": "",
                "m_childrenId": 1,
                "m_icon": "icon-group group",
                "m_url": "暂时空",
                "m_time": 1527748186000,
                "m_text": "客户管理",
                "m_sort": 1,
                "m_level": 0,
                "m_statu": 0,
                "children": [
                    {
                        "m_id": 36,
                        "m_name": "测试一",
                        "m_code": "",
                        "m_childrenId": 32,
                        "m_icon": "icon-cog",
                        "m_url": "",
                        "m_time": null,
                        "m_text": "",
                        "m_sort": 0,
                        "m_level": 0,
                        "m_statu": 0,
                        "children": [
                            
                        ]
                    },
                    {
                        "m_id": 37,
                        "m_name": "测试第二",
                        "m_code": "",
                        "m_childrenId": 32,
                        "m_icon": "icon-cog",
                        "m_url": "",
                        "m_time": null,
                        "m_text": "",
                        "m_sort": 0,
                        "m_level": 0,
                        "m_statu": 0,
                        "children": [
                            
                        ]
                    }
                ]
            }
        ]
    },
    {
        "m_id": 2,
        "m_name": "工具",
        "m_code": "002",
        "m_childrenId": 0,
        "m_icon": "fa fa-cubes fa-2x",
        "m_url": "ww.baidu.com",
        "m_time": 1527557191000,
        "m_text": "",
        "m_sort": 0,
        "m_level": 0,
        "m_statu": 0,
        "children": [
            {
                "m_id": 33,
                "m_name": "工作日志",
                "m_code": "",
                "m_childrenId": 2,
                "m_icon": "icon-building",
                "m_url": "暂空",
                "m_time": 1527748268000,
                "m_text": "工作日志描述",
                "m_sort": 2,
                "m_level": 0,
                "m_statu": 0,
                "children": [
                    
                ]
            }
        ]
    },
    {
        "m_id": 3,
        "m_name": "数据统计",
        "m_code": "003",
        "m_childrenId": 0,
        "m_icon": "fa fa-bar-chart fa-2x",
        "m_url": "ww.baidu.com",
        "m_time": 1527557191000,
        "m_text": "",
        "m_sort": 0,
        "m_level": 0,
        "m_statu": 0,
        "children": [
            {
                "m_id": 34,
                "m_name": "客户统计",
                "m_code": "",
                "m_childrenId": 3,
                "m_icon": "icon-chart-pie",
                "m_url": "暂空",
                "m_time": 1527748323000,
                "m_text": "客户统计",
                "m_sort": 3,
                "m_level": 0,
                "m_statu": 0,
                "children": [
                    
                ]
            }
        ]
    },
    {
        "m_id": 4,
        "m_name": "系统管理",
        "m_code": "004",
        "m_childrenId": 0,
        "m_icon": "fa fa-cog fa-2x",
        "m_url": "ww.baidu.com",
        "m_time": 1527557191000,
        "m_text": "",
        "m_sort": 0,
        "m_level": 0,
        "m_statu": 0,
        "children": [
            {
                "m_id": 35,
                "m_name": "系统管理",
                "m_code": "",
                "m_childrenId": 4,
                "m_icon": "icon-cog",
                "m_url": "暂空",
                "m_time": 1527748369000,
                "m_text": "系统管理描述",
                "m_sort": 4,
                "m_level": 0,
                "m_statu": 0,
                "children": [
                    
                ]
            }
        ]
    },
    {
        "m_id": 5,
        "m_name": "更多",
        "m_code": "005",
        "m_childrenId": 0,
        "m_icon": "fa fa-list fa-2x",
        "m_url": "ww.baidu.com",
        "m_time": 1527557192000,
        "m_text": "",
        "m_sort": 0,
        "m_level": 0,
        "m_statu": 0,
        "children": [
            
        ]
    }

]}

以上是官方要求的json 格式,我返回的json格式有两个bug 第一问题:menu必须是rows 第二问题:menus 必须是children ,

如果你是使用的第一种json数据格式那么menu对象干掉 menus改为children

如果你是用的第二种json格式那么menu必须是rows menus改为children

以上就是我遇到的问题,希望能给同学带来帮助 六一儿童节快乐!


猜你喜欢

转载自blog.csdn.net/Nicholas_long/article/details/80538369