• js 解析JSON


    // 初始化菜单栏
    function initMenu(menu) {
        var result = eval("(" + menu + ")");
        var data = result.data[0].children;
        if (data.length == 0) {
            self.location = "/logout.jsp";
            return;
        }
        // 加载菜单栏
        for ( var i = 0; i < data.length; i++) {
            var content = "<div style='margin: 10px;'>";
            for (var j = 0; j < data[i].children.length; j++) {
                if (data[i].children[j].value.indexOf("-") == 0)
                    continue;
                content += "<div style='margin: 5px;'><a href='#' onclick="javascript: addTab('"
                        + data[i].children[j].name
                        + "', '"
                        + data[i].children[j].value.replace("(.*)", "")
                        + "');">"
                        + data[i].children[j].name + "</a></div>";
            }
            content += "</div>";
            $("#manage-console").accordion("add", {
                id : data[i].value,
                title : data[i].name,
                content : content,
                selected : false
            });
        }
    }
    <scripttype="text/javascript">//初始化$(function(){
        initMenu('{
            "data": [
                {
                    "children": [
                        {
                            "children": [
                                {
                                    "id": "MN03004",
                                    "leaf": true,
                                    "name": "部门管理",
                                    "status": 0,
                                    "value": "/admin/hr/company(.*).action?companyID=0c522986-67ed-4ae2-8fcc-31dbe5e1ccf8",
                                    "version": 0
                                },
                                {
                                    "id": "MN03003",
                                    "leaf": true,
                                    "name": "子部门管理",
                                    "status": 0,
                                    "value": "/admin/hr/position(.*).action?companyID=0c522986-67ed-4ae2-8fcc-31dbe5e1ccf8",
                                    "version": 0
                                },
                                {
                                    "id": "MN03005",
                                    "leaf": true,
                                    "name": "人员管理",
                                    "status": 0,
                                    "value": "/admin/hr/employee(.*).action?companyID=0c522986-67ed-4ae2-8fcc-31dbe5e1ccf8",
                                    "version": 0
                                },
                                {
                                    "id": "MN03020",
                                    "leaf": true,
                                    "name": "报表管理",
                                    "status": 0,
                                    "value": "/admin/hr/report(.*).action?companyID=0c522986-67ed-4ae2-8fcc-31dbe5e1ccf8",
                                    "version": 0
                                },
                                {
                                    "id": "MN03023",
                                    "leaf": true,
                                    "name": "待办事项提醒",
                                    "status": 0,
                                    "value": "/admin/hr/task(.*).action?companyID=0c522986-67ed-4ae2-8fcc-31dbe5e1ccf8",
                                    "version": 0
                                }
                            ],
                            "id": "MG03004",
                            "leaf": false,
                            "name": "公司A",
                            "status": 0,
                            "version": 0
                        },
                        {
                            "children": [
                                {
                                    "id": "MN03009",
                                    "leaf": true,
                                    "name": "部门管理",
                                    "status": 0,
                                    "value": "/admin/hr/company(.*).action?companyID=4f079250-de19-4096-8f4d-ddc288a9e74e",
                                    "version": 0
                                },
                                {
                                    "id": "MN03010",
                                    "leaf": true,
                                    "name": "子部门管理",
                                    "status": 0,
                                    "value": "/admin/hr/position(.*).action?companyID=4f079250-de19-4096-8f4d-ddc288a9e74e",
                                    "version": 0
                                },
                                {
                                    "id": "MN03011",
                                    "leaf": true,
                                    "name": "人员管理",
                                    "status": 0,
                                    "value": "/admin/hr/employee(.*).action?companyID=4f079250-de19-4096-8f4d-ddc288a9e74e",
                                    "version": 0
                                },
                                {
                                    "id": "MN03018",
                                    "leaf": true,
                                    "name": "报表管理",
                                    "status": 0,
                                    "value": "/admin/hr/report(.*).action?companyID=4f079250-de19-4096-8f4d-ddc288a9e74e",
                                    "version": 0
                                },
                                {
                                    "id": "MN03019",
                                    "leaf": true,
                                    "name": "待办事项提醒",
                                    "status": 0,
                                    "value": "/admin/hr/task(.*).action?companyID=4f079250-de19-4096-8f4d-ddc288a9e74e",
                                    "version": 0
                                }
                            ],
                            "id": "MG03006",
                            "leaf": false,
                            "name": "公司B",
                            "status": 0,
                            "version": 0
                        },
                        {
                            "children": [
                                {
                                    "id": "MN03012",
                                    "leaf": true,
                                    "name": "部门管理",
                                    "status": 0,
                                    "value": "/admin/hr/company(.*).action?companyID=7dc063d8-94ef-43a8-8a31-8a8cc0384f3f",
                                    "version": 0
                                },
                                {
                                    "id": "MN03013",
                                    "leaf": true,
                                    "name": "子部门管理",
                                    "status": 0,
                                    "value": "/admin/hr/position(.*).action?companyID=7dc063d8-94ef-43a8-8a31-8a8cc0384f3f",
                                    "version": 0
                                },
                                {
                                    "id": "MN03014",
                                    "leaf": true,
                                    "name": "人员管理",
                                    "status": 0,
                                    "value": "/admin/hr/employee(.*).action?companyID=7dc063d8-94ef-43a8-8a31-8a8cc0384f3f",
                                    "version": 0
                                },
                                {
                                    "id": "MN03021",
                                    "leaf": true,
                                    "name": "报表管理",
                                    "status": 0,
                                    "value": "/admin/hr/report(.*).action?companyID=7dc063d8-94ef-43a8-8a31-8a8cc0384f3f",
                                    "version": 0
                                },
                                {
                                    "id": "MN03024",
                                    "leaf": true,
                                    "name": "待办事项提醒",
                                    "status": 0,
                                    "value": "/admin/hr/task(.*).action?companyID=7dc063d8-94ef-43a8-8a31-8a8cc0384f3f",
                                    "version": 0
                                }
                            ],
                            "id": "MG03007",
                            "leaf": false,
                            "name": "公司C",
                            "status": 0,
                            "version": 0
                        },
                        {
                            "children": [
                                {
                                    "id": "MN03015",
                                    "leaf": true,
                                    "name": "部门管理",
                                    "status": 0,
                                    "value": "/admin/hr/company(.*).action?companyID=b50c3ae9-47ef-4bd6-b38d-6c8654cf421d",
                                    "version": 0
                                },
                                {
                                    "id": "MN03016",
                                    "leaf": true,
                                    "name": "子部门管理",
                                    "status": 0,
                                    "value": "/admin/hr/position(.*).action?companyID=b50c3ae9-47ef-4bd6-b38d-6c8654cf421d",
                                    "version": 0
                                },
                                {
                                    "id": "MN03017",
                                    "leaf": true,
                                    "name": "人员管理",
                                    "status": 0,
                                    "value": "/admin/hr/employee(.*).action?companyID=b50c3ae9-47ef-4bd6-b38d-6c8654cf421d",
                                    "version": 0
                                },
                                {
                                    "id": "MN03022",
                                    "leaf": true,
                                    "name": "报表管理",
                                    "status": 0,
                                    "value": "/admin/hr/report(.*).action?companyID=b50c3ae9-47ef-4bd6-b38d-6c8654cf421d",
                                    "version": 0
                                },
                                {
                                    "id": "MN03025",
                                    "leaf": true,
                                    "name": "待办事项提醒",
                                    "status": 0,
                                    "value": "/admin/hr/task(.*).action?companyID=b50c3ae9-47ef-4bd6-b38d-6c8654cf421d",
                                    "version": 0
                                }
                            ],
                            "id": "MG03008",
                            "leaf": false,
                            "name": "公司D",
                            "status": 0,
                            "version": 0
                        },
                        {
                            "children": [
                                {
                                    "id": "MN03008",
                                    "leaf": true,
                                    "name": "同步数据",
                                    "status": 0,
                                    "value": "/admin/hr/companySyncEap.action",
                                    "version": 0
                                }
                            ],
                            "id": "MG03005",
                            "leaf": false,
                            "name": "系统管理",
                            "status": 0,
                            "version": 0
                        }
                    ],
                    "id": "MG03",
                    "leaf": false,
                    "name": "人事系统",
                    "status": 0,
                    "version": 0
                }
            ],
            "success": true
        }');
    });</script>
    View JSON Code
    // 打开Tab页
    function addTab(title, uri) {
        if(uri.indexOf("_") == 0)
            window.open(uri.substring(1));
        else {
            $("#manage-tabs").tabs("close", title);
            uri += uri.indexOf("?") > -1 ? "&" : "?";
            uri += "rand=" + Math.random();
            $("#manage-tabs").tabs("add", {
                title : title,
                content : "<iframe scrolling='auto' src='" + uri + "' frameborder='0' style='100%; height:100%;'></iframe>",
                closable : true
            });
        }
    }
    View addTab()
  • 相关阅读:
    Java版远程控制V1.0
    Struts2使用Kindeditor4.0.3在线编辑器上传图片、视频、FLASH、附件
    给你的网站加上站内搜索Spring+Hibernate基于Compass(基于Lucene)实现
    Hibernate整合进spring使用自己的事务处理
    Hibernate整合进spring使用hibernateTemplate.getSessionFactory().getCurrentSession()理解
    GWT(Google Web Toolkit)入门学习
    转载:狼与哈士奇
    [转]远程桌面无法连接上(管理员已结束了会话)的解决方法
    ibmDW:凤凰涅槃:从 iBatis 到 MyBatis
    hibernate多对多映射拆成2个一对多映射(注解)
  • 原文地址:https://www.cnblogs.com/yushouling/p/4871560.html
Copyright © 2020-2023  润新知