`
umgsai
  • 浏览: 110409 次
  • 性别: Icon_minigender_1
  • 来自: 广州
文章分类
社区版块
存档分类
最新评论

JsTree使用笔记

阅读更多

menu主界面效果图如下



 中间的树形菜单使用了基于JQuery的jsTree

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<?php
require '../connect.php';
?>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title>管理中心</title>
        <style type="text/css">
            <!--
            body {
                margin-left: 0px;
                margin-top: 0px;
                margin-right: 0px;
                margin-bottom: 0px;
                font-size: 12px;
            }
            -->
        </style>
        <script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
        <script type="text/javascript" src="js/jquery.jstree.js"></script>
        <script type="text/javascript" class="source">
            $(function() {
                $("#create_1").click(function() {
                    $("#demo1").jstree("create");
                });
                $("#create_2").click(
                        function() {
                            $("#demo1").jstree("create", "#phtml_1", "first",
                                    "Enter a new name");
                        });

                $("#demo1").jstree({
                    "ui": {
                        //"initially_select": ["phtml_2"]
                        //默认选中的项
                    },
                    "crrm": {
                        "input_width_limit": 50
                    },
                    "themes": {
                        "theme": "classic",
                        "dots": true,
                        "icons": true
                    },
                    "core": {
                        //"initially_open": ["phtml_1", "phtml_4"]
                    }, //默认展开的项
                    "plugins": ["themes", "html_data", "ui", "crrm", "contextmenu"],
                    "contextmenu": {
                        "items": {
                            "create": {
                                "label": "新增",
                                "action": function(obj) {
                                    //alert($(obj).attr("leaf"));
                                    var aaa = $(obj).attr("leaf");
//                                                    alert($(obj).children().length);
//alert($(obj).children().eq(1).text());
                                    if ($.trim($(obj).children().eq(1).text()) == "保护巡检台账" || $.trim($(obj).children().eq(1).text()) == "运行注意事项" || $.trim($(obj).children().eq(1).text()) == "维护记录") {
                                        alert("此处不可添加子菜单");
                                        return;
                                    }
                                    //alert(aaa);
                                    if (aaa == 5) {//第五级不可以再添加子级
                                        alert("不允许再此处添加子级");
                                        return;
                                        //alert(12);
                                    } else if (aaa == 2) {
                                        //alert($(obj).parent().parent().children().eq(1).text()); 
                                        //取到上一级的名字
                                        var p_name = $(obj).parent().parent().children().eq(1).text();
                                        p_name = $.trim(p_name);
										//alert(p_name);
                                        if (p_name.indexOf("变电站") >= 0) {
                                            //alert("上一级的名字不包含变电站");
                                            //自动添加18项菜单
                                            if ($(obj).children().length != 2) {
                                                alert("存在子节点,请先删除子节点后再添加");
                                                return;
                                            }
											if(p_name.indexOf("220") >= 0){
												var names = new Array("线路保护", "旁路保护", "母线保护", "失灵保护", "变压器保护", "母联及分段开关保护", "所变保护", "电容器保护", "稳定装置", "故障录波器", "低周减载装置", "备用电源自动投入装置", "辅助保护", "故障信息子站", "保护巡检台账", "运行注意事项", "维护记录", "综自台账");
											}else{
												var names = new Array("线路保护", "旁路保护", "母线保护"/*, "失灵保护"*/, "变压器保护", "母联及分段开关保护", "所变保护", "电容器保护",/* "稳定装置",*/ "故障录波器", "低周减载装置", "备用电源自动投入装置", "辅助保护", /*"故障信息子站",*/ "保护巡检台账", "运行注意事项", "维护记录", "综自台账");
											
											}
                                            
                                            //var args = {"time": new Date(), "p_id": p_id, "name": name, "leaf_id": leaf_id};
                                            //alert(p_id + "  ");
                                            var name_all = "";
                                            for (var i = 0; i < names.length; i++) {
                                                name_all += (names[i] + ",");
                                                //create事件会出发后面的create方法
                                                var o = this.create(obj, 'last', {
                                                    attr: {
                                                        ntype: 'leaf', //叶子节点
                                                        bbb: '123456'//test
                                                    },
                                                    data: names[i]
                                                });
                                                $(o).attr("flag", "piliang18");//批量生成18项菜单需要特殊处理
                                            }
                                            //alert("已自动添加15项子菜单");
                                            // alert(name_all);
                                            var url = "piliang18_add.php";
                                            var p_id = $(obj).attr("n_id");
                                            var leaf_id = $(obj).attr("leaf");
                                            var args = {"time": new Date(), "p_id": p_id, "name": name_all, "leaf_id": leaf_id, "pageUrl": "#"};
                                            $.ajax({
                                                type: "GET",
                                                url: url,
                                                dataType: "json",
                                                data: args,
                                                success: function(msg) {
                                                    if (msg.error) {
                                                        alert(msg.error);
                                                        window.location.reload();//刷新页面
                                                    } else if (msg.success) {
                                                        window.location.reload();//刷新页面
                                                    }
                                                    //window.location.reload();//刷新页面
                                                }});
//                                                            window.location.reload();//刷新页面
                                            return;
                                        } else {
                                            //alert("上一级的名字不包含变电站");
                                        }

                                    } else if (aaa == 3) {
//                                                        alert(3);
                                        var this_name = $(obj).children().eq(1).text();
//                                                        alert(this_name);
                                        if ($.trim(this_name) == "综自台账") {
//                                                            alert(this_name);
                                            var names = new Array("综自报告", "综自台账", "综自数据备份", "综自维护记录");
                                            for (var i = 0; i < names.length; i++) {
                                                var o = this.create(obj, 'last', {
                                                    attr: {
                                                        ntype: 'leaf'//叶子节点
                                                    },
                                                    data: names[i]
                                                });
                                                //给生成的节点加上页面链接地址
                                                if (i == 0) {
                                                    $(o).attr("page", "input/sub_zzbgupload.php");
                                                } else if (i == 1) {
                                                    $(o).attr("page", "input/sub_zztzupload.php");
                                                } else if (i == 2) {
                                                    $(o).attr("page", "input/sub_zzsjbfupload.php");
                                                } else if (i == 3) {
                                                    $(o).attr("page", "input/sub_zzwhjl_list.php");
                                                }
                                            }
                                            return;//如果是综自台账,则不在下面生成“名称”一项
                                        }

                                    } else if (aaa == 4) {//第4级,上级是“线路保护”										
										if ($(obj).children().length != 2) {
                                            alert("存在子节点,请先删除子节点后再添加");
                                            return;
                                        }
                                        var p_name = $(obj).parent().parent().children().eq(1).text();
                                        p_name = $.trim(p_name);
                                        //alert(p_name);
                                        if (p_name == "线路保护") {
                                            var n_name = $(obj).children().eq(1).text();
                                            n_name = $.trim(n_name);
                                            if (n_name.indexOf("220") >= 0) {
                                                var names = new Array("图纸", "说明书", "第一套保护台账", "第二套保护台账", "报告模板", "定值");
                                                for (var i = 0; i < names.length; i++) {
                                                    //create事件会出发后面的create方法
                                                    //"第一套保护台账", "第二套保护台账" 对应的是input/xianlubaohu1.php页面
                                                    if (i == 2 || i == 3) {
                                                        //o是新生成的那个节点
                                                        var o = this.create(obj, 'last', {
                                                            attr: {
                                                                ntype: 'leaf'//叶子节点
                                                                        //page:'input/xianlubaohu1.php'
                                                            },
                                                            data: names[i]
                                                        });
                                                        //给生成的节点加上页面链接地址
                                                        $(o).attr("page", "input/xianlubaohu1.php");
                                                        continue;
                                                    }
                                                    //o是新生成的那个节点
                                                    var o = this.create(obj, 'last', {
                                                        attr: {
                                                            ntype: 'leaf'//叶子节点
                                                        },
                                                        data: names[i]
                                                    });
                                                    //给生成的节点加上页面链接地址
                                                    $(o).attr("page", "input/upload.php");
                                                }
                                                return;
                                            } else {
                                                var names = new Array("图纸", "说明书", "保护台账", "报告模板", "定值");
                                                for (var i = 0; i < names.length; i++) {
                                                    //create事件会出发后面的create方法
                                                    if (i == 2) {
                                                        //o是新生成的那个节点
                                                        var o = this.create(obj, 'last', {
                                                            attr: {
                                                                ntype: 'leaf'//叶子节点
                                                            },
                                                            data: names[i]
                                                        });
                                                        //给生成的节点加上页面链接地址
                                                        $(o).attr("page", "input/xianlubaohu2.php");
                                                        continue;
                                                    }
                                                    //o是新生成的那个节点
                                                    var o = this.create(obj, 'last', {
                                                        attr: {
                                                            ntype: 'leaf'//叶子节点
                                                        },
                                                        data: names[i]
                                                    });
                                                    //给生成的节点加上页面链接地址
                                                    $(o).attr("page", "input/upload.php");
                                                }
                                                return;
                                            }
                                        } else if (p_name == "旁路保护") {
                                            var names = new Array("图纸", "说明书", "保护台账", "报告模板", "定值");
                                            for (var i = 0; i < names.length; i++) {
                                                var o = this.create(obj, 'last', {
                                                    attr: {
                                                        ntype: 'leaf'//叶子节点
                                                    },
                                                    data: names[i]
                                                });
                                                if (i == 2) {
                                                    //给生成的节点加上页面链接地址
                                                    $(o).attr("page", "input/panglubaohu1.php");
                                                } else {
                                                    //给生成的节点加上页面链接地址
                                                    $(o).attr("page", "input/upload.php");
                                                }
                                            }
                                            return;
                                        } else if ($.trim(p_name) == "母线保护") {
                                            var n_name = $(obj).children().eq(1).text();
                                            n_name = $.trim(n_name);
                                            if (n_name.indexOf("220") >= 0) {
                                                var names = new Array("图纸", "说明书", "第一套保护台账", "第二套保护台账", "报告模板", "定值");
                                                for (var i = 0; i < names.length; i++) {
                                                    var o = this.create(obj, 'last', {
                                                        attr: {
                                                            ntype: 'leaf'//叶子节点
                                                        },
                                                        data: names[i]
                                                    });
                                                    if (i == 2 || i == 3) {
                                                        $(o).attr("page", "input/muxianbaohu1.php");
                                                    } else {
                                                        $(o).attr("page", "input/upload.php");
                                                    }
                                                }
                                            } else {
                                                var names = new Array("图纸", "说明书", "保护台账", "报告模板", "定值");
                                                for (var i = 0; i < names.length; i++) {
                                                    var o = this.create(obj, 'last', {
                                                        attr: {
                                                            ntype: 'leaf'//叶子节点
                                                        },
                                                        data: names[i]
                                                    });
                                                    if (i == 2) {
                                                        $(o).attr("page", "input/muxianbaohu2.php");
                                                    } else {
                                                        $(o).attr("page", "input/upload.php");
                                                    }
                                                }
                                            }
                                            return;
                                        } else if (p_name == "失灵保护") {
                                            var names = new Array("图纸", "说明书", "保护台账", "报告模板", "定值");
                                            for (var i = 0; i < names.length; i++) {
                                                var o = this.create(obj, 'last', {
                                                    attr: {
                                                        ntype: 'leaf'//叶子节点
                                                    },
                                                    data: names[i]
                                                });
                                                if (i == 2) {
                                                    $(o).attr("page", "input/shilingbaohu1.php");
                                                } else {
                                                    $(o).attr("page", "input/upload.php");
                                                }
                                            }
                                            return;
                                        } else if (p_name == "变压器保护") {
                                            var names = new Array("图纸", "说明书", "第一套保护台账", "第二套保护台账", "第三套保护台账", "报告模板", "定值");
                                            for (var i = 0; i < names.length; i++) {
                                                var o = this.create(obj, 'last', {
                                                    attr: {
                                                        ntype: 'leaf'//叶子节点
                                                    },
                                                    data: names[i]
                                                });
                                                if (i == 2 || i == 3 || i == 4) {
                                                    $(o).attr("page", "input/bianyaqibaohu1.php");
                                                } else {
                                                    $(o).attr("page", "input/upload.php");
                                                }
                                            }
                                            return;
                                        } else if (p_name == "母联及分段开关保护") {
                                            var n_name = $(obj).children().eq(1).text();
                                            n_name = $.trim(n_name);
                                            if (n_name.indexOf("220") >= 0) {
                                                var names = new Array("图纸", "说明书", "第一套保护台账", "第二套保护台账", "报告模板", "定值");
                                                for (var i = 0; i < names.length; i++) {
                                                    var o = this.create(obj, 'last', {
                                                        attr: {
                                                            ntype: 'leaf'//叶子节点
                                                        },
                                                        data: names[i]
                                                    });
                                                    if (i == 2 || i == 3) {
                                                        $(o).attr("page", "input/mulianjifenduan1.php");
                                                    } else {
                                                        $(o).attr("page", "input/upload.php");
                                                    }
                                                }
                                            } else {
                                                var names = new Array("图纸", "说明书", "保护台账", "报告模板", "定值");
                                                for (var i = 0; i < names.length; i++) {
                                                    var o = this.create(obj, 'last', {
                                                        attr: {
                                                            ntype: 'leaf'//叶子节点
                                                        },
                                                        data: names[i]
                                                    });
                                                    if (i == 2) {
                                                        $(o).attr("page", "input/mulianjifenduan2.php");
                                                    } else {
                                                        $(o).attr("page", "input/upload.php");
                                                    }
                                                }
                                            }
                                            return;
                                        } else if (p_name == "稳定装置") {
                                            var names = new Array("图纸", "说明书", "保护台账", "报告模板", "定值");
                                            for (var i = 0; i < names.length; i++) {
                                                var o = this.create(obj, 'last', {
                                                    attr: {
                                                        ntype: 'leaf'//叶子节点
                                                    },
                                                    data: names[i]
                                                });
                                                if (i == 2) {
                                                    $(o).attr("page", "input/wendingzhuangzhi1.php");
                                                } else {
                                                    $(o).attr("page", "input/upload.php");
                                                }
                                            }
                                            return;
                                        } else if (p_name == "故障录波器") {
                                            var names = new Array("图纸", "说明书", "保护台账", "报告模板", "定值");
                                            for (var i = 0; i < names.length; i++) {
                                                var o = this.create(obj, 'last', {
                                                    attr: {
                                                        ntype: 'leaf'//叶子节点
                                                    },
                                                    data: names[i]
                                                });
                                                if (i == 2) {
                                                    $(o).attr("page", "input/guzhangluboqi1.php");
                                                } else {
                                                    $(o).attr("page", "input/upload.php");
                                                }
                                            }
                                            return;
                                        } else if (p_name == "低周减载装置") {
                                            var names = new Array("图纸", "说明书", "保护台账", "报告模板", "定值");
                                            for (var i = 0; i < names.length; i++) {
                                                var o = this.create(obj, 'last', {
                                                    attr: {
                                                        ntype: 'leaf'//叶子节点
                                                    },
                                                    data: names[i]
                                                });
                                                if (i == 2) {
                                                    $(o).attr("page", "input/dizhoujianzaizhuangzhi1.php");
                                                } else {
                                                    $(o).attr("page", "input/upload.php");
                                                }
                                            }
                                            return;
                                        } else if (p_name == "所变保护") {
                                            var names = new Array("图纸", "说明书", "保护台账", "报告模板", "定值");
                                            for (var i = 0; i < names.length; i++) {
                                                var o = this.create(obj, 'last', {
                                                    attr: {
                                                        ntype: 'leaf'//叶子节点
                                                    },
                                                    data: names[i]
                                                });
                                                if (i == 2) {
                                                    $(o).attr("page", "input/suobian_dianrongqi.php");
                                                } else {
                                                    $(o).attr("page", "input/upload.php");
                                                }
                                            }
                                            return;
                                        } else if (p_name == "电容器保护") {
                                            var names = new Array("图纸", "说明书", "保护台账", "报告模板", "定值");
                                            for (var i = 0; i < names.length; i++) {
                                                var o = this.create(obj, 'last', {
                                                    attr: {
                                                        ntype: 'leaf'//叶子节点
                                                    },
                                                    data: names[i]
                                                });
                                                if (i == 2) {
                                                    $(o).attr("page", "input/suobian_dianrongqi.php");
                                                } else {
                                                    $(o).attr("page", "input/upload.php");
                                                }
                                            }
                                            return;
                                        } else if (p_name == "备用电源自动投入装置") {
                                            var names = new Array("图纸", "说明书", "保护台账", "报告模板", "定值");
                                            for (var i = 0; i < names.length; i++) {
                                                var o = this.create(obj, 'last', {
                                                    attr: {
                                                        ntype: 'leaf'//叶子节点
                                                    },
                                                    data: names[i]
                                                });
                                                if (i == 2) {
                                                    $(o).attr("page", "input/beiyongdianyuanzidongtouruzhuangzhi1.php");
                                                } else {
                                                    $(o).attr("page", "input/upload.php");
                                                }
                                            }
                                            return;
                                        } else if (p_name == "故障信息子站") {
                                            var names = new Array("图纸", "说明书", "保护台账", "报告模板", "定值");
                                            for (var i = 0; i < names.length; i++) {
                                                var o = this.create(obj, 'last', {
                                                    attr: {
                                                        ntype: 'leaf'//叶子节点
                                                    },
                                                    data: names[i]
                                                });
                                                if (i == 2) {
                                                    $(o).attr("page", "input/guzhangxinxizizhan1.php");
                                                } else {
                                                    $(o).attr("page", "input/upload.php");
                                                }
                                            }
                                            return;
                                        }else if (p_name == "辅助保护") {
                                            var names = new Array("图纸", "说明书", "保护台账", "报告模板", "定值");
                                            for (var i = 0; i < names.length; i++) {
                                                var o = this.create(obj, 'last', {
                                                    attr: {
                                                        ntype: 'leaf'//叶子节点
                                                    },
                                                    data: names[i]
                                                });
                                                if (i == 2) {
                                                    $(o).attr("page", "input/fuzhubaohutaizhang.php");
                                                } else {
                                                    $(o).attr("page", "input/upload.php");
                                                }
                                            }
                                            return;
                                        }/*
                                         else if(p_name == "保护巡检台账"){
                                         var names = new Array("图纸", "说明书", "保护台账", "报告模板", "定值");
                                         for (var i = 0; i < names.length; i++) {
                                         var o = this.create(obj, 'last', {
                                         attr: {
                                         ntype: 'leaf'//叶子节点
                                         },
                                         data: names[i]
                                         });
                                         if (i == 2) {
                                         $(o).attr("page", "input/bhxjtzupload.php");
                                         } else {
                                         $(o).attr("page", "input/upload.php");
                                         }
                                         }
                                         return;
                                         }else if(p_name == "运行注意事项"){
                                         var names = new Array("图纸", "说明书", "保护台账", "报告模板", "定值");
                                         for (var i = 0; i < names.length; i++) {
                                         var o = this.create(obj, 'last', {
                                         attr: {
                                         ntype: 'leaf'//叶子节点
                                         },
                                         data: names[i]
                                         });
                                         if (i == 2) {
                                         $(o).attr("page", "input/yxzzsxupload.php");
                                         } else {
                                         $(o).attr("page", "input/upload.php");
                                         }
                                         }
                                         return;
                                         }else if(p_name == "维护记录"){
                                         var names = new Array("图纸", "说明书", "保护台账", "报告模板", "定值");
                                         for (var i = 0; i < names.length; i++) {
                                         var o = this.create(obj, 'last', {
                                         attr: {
                                         ntype: 'leaf'//叶子节点
                                         },
                                         data: names[i]
                                         });
                                         if (i == 2) {
                                         $(o).attr("page", "input/whjl_list.php");
                                         } else {
                                         $(o).attr("page", "input/upload.php");
                                         }
                                         }
                                         return;
                                         }else if(p_name == "综自台账"){
                                         var names = new Array("综自报告", "综自台账", "综自数据备份", "综自维护记录");
                                         for (var i = 0; i < names.length; i++) {
                                         var o = this.create(obj, 'last', {
                                         attr: {
                                         ntype: 'leaf'//叶子节点
                                         },
                                         data: names[i]
                                         });
                                         if (i == 0) {
                                         $(o).attr("page", "input/sub_zzbgupload.php");
                                         } else if (i == 1) {
                                         $(o).attr("page", "input/sub_zztzupload.php");
                                         }else if (i == 2) {
                                         $(o).attr("page", "input/sub_zzsjbfupload.php");
                                         }else if (i == 3) {
                                         $(o).attr("page", "input/sub_zzwhjl_list.php");
                                         }
                                         }
                                         return;
                                         }
                                         */

                                    }
                                    this.create(obj, 'last', {
                                        attr: {
                                            ntype: 'leaf'//叶子节点
                                        },
                                        data: '名称'
                                    });

                                    //alert($(obj).data);
                                }
                            },
                            "rename": {
                                "label": "重命名"/*,
                                 "action": function(obj) {
                                 var id = $(obj).attr("n_id");//当前节点的id
                                 var name = $(obj).text();
                                 }*/
                            },
                            "remove": {
                                "label": "删除",
                                "action": function(obj) {
                                    if ($(obj).attr("leaf") == 1) {
                                        alert("不允许删除根节点");
                                        return;
                                    }
                                    if (!confirm("确认删除吗?")) {
                                        return;
                                    } else {
                                        //$("#demo1").jstree("remove", obj);
                                        var n_id = $(obj).attr("n_id");//当前节点的id

                                        var url = "delete.php";
                                        //var url = "add.php?p_id=" + p_id + "&name=" + name;
                                        var args = {"time": new Date(), "n_id": n_id};
                                        $.ajax({
                                            type: "GET",
                                            url: url,
                                            dataType: "json",
                                            data: args,
                                            success: function(msg) {
                                                if (msg.error) {
                                                    alert(msg.error);
//                                                                    window.location.reload();//刷新页面
                                                    return;
                                                }
                                                //alert("删除成功");
                                                $("#demo1").jstree("remove", obj);
                                            }
                                        });
                                    }
                                }
                            },
                            "ccp": null/*
                             , "add_pro": {
                             "label": "编辑属性",
                             "action": function(obj) {
                             var n_id = $(obj).attr("n_id");//当前节点的id
                             var name = $(obj).text();
                             var pro;
                             var url = "getPro.php";
                             var args = {"time": new Date(), "n_id": n_id};
                             $.ajax({
                             type: "GET",
                             url: url,
                             dataType: "json",
                             data: args,
                             success: function(msg) {
                             //alert(msg.url);
                             if (msg.error) {
                             alert(msg.error);
                             return;
                             }
                             pro = prompt("请添加本项的超链接", msg.url);
                             if (!pro && typeof (pro) != "undefined" && pro != 0) {
                             return;
                             }
                                             
                             //alert(pro);
                             $.ajax({
                             type: "GET",
                             url: "updatePro.php",
                             dataType: "json",
                             data: {"time": new Date(), "n_id": n_id, "url": pro},
                             success: function(msg) {
                             //$(obj).attr("href", msg.url);
                             $(obj).children().eq(1).attr("href", pro);
                             }
                             });
                             }
                             });
                             //alert(pro);
                             }
                             }*/
                        }
                    }

                }).bind("create.jstree", function(e, data) {
                    var nodeData = {
                        name: data.rslt.name
                    };
                    //alert(data.rslt.name)
                    //alert($(data.rslt.obj).attr("page"));
                    //如果对应的页面地址已经提前自动设置,就把这个pageUrl存到数据库里去
//                                    alert($(data.rslt.obj).attr("flag"));
                    if ($(data.rslt.obj).attr("flag")) {
                        //批量生成18项菜单需特殊处理
                        return;
                    }
                    var pageUrl = $(data.rslt.obj).attr("page");
                    if (pageUrl != null) {
                        pageUrl = $.trim(pageUrl);
                    } else {
                        pageUrl = "#";
                    }
                    if (data.rslt.name.length > 50) {
                        alert("名称不能大于50个字符!");
                        window.setTimeout(function() {
                            $("#demo1").jstree("rename", data.rslt.obj);
                        }, 100);
                        return;
                    }
                    var leaf_id = $(data.rslt.obj).parent().parent().attr("leaf");//上一级的leaf,当前级的leaf应该加1,到服务器上再加1
                    var p_id = $(data.rslt.obj).parent().parent().attr("n_id");//父节点的n_id
                    var name = data.rslt.name;
                    //alert(name);
                    /*此处已在piliang18_add.php中处理
                     if (name == "保护巡检台账") {
                     pageUrl = "input/bhxjtzupload.php";
                     } else if (name == "运行注意事项") {
                     pageUrl = "input/yxzzsxupload.php";
                     } else if (name == "维护记录") {
                     pageUrl = "input/whjl_list.php";
                     }
                     */
                    var url = "add.php";
                    var args = {"time": new Date(), "p_id": p_id, "name": name, "leaf_id": leaf_id, "pageUrl": pageUrl};
                    $.ajax({
                        type: "GET",
                        url: url,
                        dataType: "json",
                        data: args,
                        success: function(msg) {
                            $(data.rslt.obj).attr("n_id", msg.id);
                            $(data.rslt.obj).attr("leaf", msg.level);
                            $(data.rslt.obj).children().eq(1).attr("href", msg.url);
//                                            $(data.rslt.obj).children().eq(1).attr("aaa", "12ddd");
                            //alert($(data.rslt.obj).children().eq(1).text());//a标签的链接文字
                            /*
                             if($(data.rslt.obj).children().eq(1).text() == "线路保护"){
                             alert('保护巡检台账');
                             //$(data.rslt.obj).children().eq(1).attr('href','input/bhxjtzupload.php');
                             }
                             */
                            //$(data.rslt.obj).children().eq(1).attr("target", "main");
                            //$(data.rslt.obj).children().eq(2).children()
//                                            alert(msg.name);
                            /*
                             if (msg.name == "保护巡检台账" || "运行注意事项" || "维护记录") {
                             $(data.rslt.obj).children().eq(1).click(function() {
                             $(parent.document).find("#main").attr("src", "menu/" + msg.url + "?n_id=" + msg.id);
                             });
                             }
                             */
                            if (msg.error) {
                                alert(msg.error);
//                                                $("#demo1").jstree("remove", data.rslt.obj);
                                window.location.reload();//刷新页面
                            }
                            if ($.trim(msg.url) != "#") {
                                $(data.rslt.obj).children().eq(1).click(function() {
                                    $(parent.document).find("#main").attr("src", "menu/" + msg.url + "?n_id=" + msg.id);
                                });
                            } else {//如果链接是#,则点击无反应
                                $(data.rslt.obj).children().eq(1).click(function() {
//                                                    return;
                                });
//                                                $(data.rslt.obj).children().eq(1).unbind("click");
                            }
                            /*
                             if (msg.level == 5) {
                             $(data.rslt.obj).children().eq(1).click(function() {
                             // alert("!!!!");
                             $(parent.document).find("#main").attr("src", "menu/" + msg.url + "?n_id=" + msg.id);
                             });
                             }
                             */
                        }
                    });
                }).bind("rename.jstree", function(e, data) {
                    if (data.rslt.new_name == data.rslt.old_name) {
                        return;
                    }
                    var n_id = $(data.rslt.obj).attr("n_id");
                    var new_name = data.rslt.new_name;
                    var url = "update.php";
                    var args = {"time": new Date(), "n_id": n_id, "new_name": new_name};
                    $.ajax({
                        type: "GET",
                        url: url,
                        dataType: "json",
                        data: args,
                        success: function(msg) {
//                                            alert(msg);
                            if (msg.error) {
                                alert(msg.error);
                                window.location.reload();//刷新页面
                            }
                        }
                    });
                });

                $("a").click(function(e) {
//                                    alert("click");
                    //alert("n_id:" + $(this).parent().attr('n_id') + "   leaf:" + $(this).parent().attr('leaf'));
                    //自定义点击事件
                    //window.location = this.href;
                    if ($(this).parent().attr('leaf') == 5) {
                        //alert( $(parent.document).find("#mainFrame").attr("src"));
                        //                        alert("叶子");
                        //var frm = window.parent.window.frames['mainFrame'];
                        //alert(frm);
                        if ($(this).attr('href') == '#') {
                            //alert("#");
                        } else {
                            var Cts = $(this).attr('href');
                            if (Cts.indexOf("type") >= 0)
                                $(parent.document).find("#main").attr("src", this.href + "?n_id=" + $(this).parent().attr("n_id"));
                            else
                                $(parent.document).find("#main").attr("src", this.href + "?n_id=" + $(this).parent().attr("n_id"));
                        }
                        return false;
                    }
                    var href = $(this).attr('href');
                    //alert(href);
                    //alert(href == "#");
                    if (href == "#") {
                        //alert("###");
                        //$(parent.document).find("#main").attr("src", "help.html");
                        return false;
                    }
                    //解决IE的兼容性问题
                    if(href.indexOf("#") > 0){
                        //$(parent.document).find("#main").attr("src", "help.html");
                        return false;
                    }
                    $(parent.document).find("#main").attr("src", this.href + "?n_id=" + $(this).parent().attr("n_id"));
//                                    e.preventDefault();
                    return false;
                    //                    alert($(this).parent().attr('leaf'));
                });



//                                $(this).find("*").click(function() {
//                                    alert($(this).text);
//                                });
                /*
                 $("li").click(function(e) {
                 //alert($.trim($(this).text()));
                                 
                 if ($.trim($(this).text()) == "交流平台" || $.trim($(this).text()) == "规程规范" || $.trim($(this).text()) == "作业指导书" || $.trim($(this).text()) == "三措一案" || $.trim($(this).text()) == "常用软件" || $.trim($(this).text()) == "仪器仪表台账" || $.trim($(this).text()) == "安装工器具台账" || $.trim($(this).text()) == "备品备件台账" || $.trim($(this).text()) == "保护巡检台账" ||) {
                 //alert('jlpt');
                 $(parent.document).find("#main").attr("src", this.href);
                 }
                                 
                 //                                    alert($(this).attr("href"));
                 if (this.href.length == 1) {
                 alert("#");
                 return false;
                 } else {
                 //$(parent.document).find("#main").attr("src", this.href);
                 return false;
                 }
                 e.preventDefault();//取消默认行为,没有这句话的话,会跳转到baidu网站上 
                 return false;
                 });
                 */

            }

            );

            function create_node() {
                alert(this.leaf);
            }
        </script>
    </head>
    <body bgcolor="#FFFFFF">
        <div id="demo1" class="demo">
            <ul>
                <?php
                //select * from menu order by CONVERT( name USING gbk ) COLLATE gbk_chinese_ci ASC ;
                $sql1 = "select * from menu where p_id = 0 order by id"; //获取根节点
                $result1 = mysql_db_query($mysql_database, $sql1, $conn);
// 获取查询结果
//                $row = mysql_fetch_row($result);
                while ($row1 = mysql_fetch_array($result1)) {
                    echo "<li id=\"phtml_1\"  leaf=\"" . $row1['level'] . "\" n_id=\"" . $row1['id'] . "\"><a href=\"" . $row1['url'] . "\">" . $row1['name'] . "</a>";
                    echo '<ul>';
                    $sql2 = "select * from menu where p_id = " . $row1['id'] . " order by CONVERT( name USING gbk ) COLLATE gbk_chinese_ci ASC";
                    $result2 = mysql_db_query($mysql_database, $sql2, $conn);
                    while ($row2 = mysql_fetch_array($result2)) {
                        echo "<li id=\"phtml_1\"  leaf=\"" . $row2['level'] . "\" n_id=\"" . $row2['id'] . "\"><a href=\"" . $row2['url'] . "\">" . $row2['name'] . "</a>";
                        echo '<ul>';
                        $sql3 = "select * from menu where p_id = " . $row2['id'] . " order by id";
                        $result3 = mysql_db_query($mysql_database, $sql3, $conn);
                        while ($row3 = mysql_fetch_array($result3)) {
							if($row3['name'] == '线路保护' || $row3['name'] == '旁路保护' || $row3['name'] == '母线保护' || $row3['name'] == '母联及分段开关保护'){
								$sql4 = "select * from menu where p_id = " . $row3['id'] . " order by id";
								$result4 = mysql_db_query($mysql_database, $sql4, $conn);
								$group220 = array();
								$group110 = array();
								$group35 = array();
								$group10 = array();
								$group_other = array();
								$group_all = array();
								while ($row4 = mysql_fetch_array($result4)) {
									//print_r($row4['name']);
									$str = substr($row4['name'],0,2);
									//echo $str.'<br/>';
									if($str == '22'){//220
										$group220[count($group220)] = $row4;
									}else if($str == '11'){//110
										$group110[count($group110)] = $row4;
									}else if($str == '35'){//35
										$group35[count($group35)] = $row4;
									}else if($str == '10'){//10
										$group10[count($group10)] = $row4;
									}else{//其他
										$group_other[count($group_other)] = $row4;
									}
								}
								$group_all = array_merge($group220, $group110, $group35, $group10, $group_other);
								//print_r($group_all);
								echo "<li id=\"phtml_1\"  leaf=\"" . $row3['level'] . "\" n_id=\"" . $row3['id'] . "\"><a href=\"" . $row3['url'] . "\">" . $row3['name'] . "</a>";
								echo '<ul>';
								for($i = 0; $i < count($group_all); $i++){
									echo "<li id=\"phtml_1\"  leaf=\"" . $group_all[$i]['level'] . "\" n_id=\"" . $group_all[$i]['id'] . "\"><a href=\"" . $group_all[$i]['url'] . "\">" . $group_all[$i]['name'] . "</a>";
										
										echo "<ul>";
										$sql5 = "select * from menu where p_id = " . $group_all[$i]['id'] . " order by id";
										$result5 = mysql_db_query($mysql_database, $sql5, $conn);
										while ($row5 = mysql_fetch_array($result5)) {
											echo "<li id='phtml_1'  leaf=\"" . $row5['level'] . "\" n_id=\"" . $row5['id'] . "\"><a href=\"" . $row5['url'] . "\"  target='main' >" . $row5['name'] . "</a>";

											echo '</li>';
										}
										echo '</ul>';
										echo '</li>';
								}
								echo '</ul>';
								echo '</li>';
								
							}else if($row3['name'] == '变压器保护' || $row3['name'] == '所变保护' || $row3['name'] == '电容器保护'){
								
								$sql4 = "select * from menu where p_id = " . $row3['id'] . " order by id";
								$result4 = mysql_db_query($mysql_database, $sql4, $conn);
								$group1 = array();
								$group2 = array();
								$group3 = array();
								$group4 = array();
								$group_other1 = array();
								$group_all = array();
								while ($row4 = mysql_fetch_array($result4)) {
									//print_r($row4['name']);
									$str = substr($row4['name'],0,2);
									//echo $str.'<br/>';
									if($str == '#1'){//220
										$group1[count($group1)] = $row4;
									}else if($str == '#2'){//110
										$group2[count($group2)] = $row4;
									}else if($str == '#3'){//35
										$group3[count($group3)] = $row4;
									}else if($str == '#4'){//10
										$group4[count($group4)] = $row4;
									}else{//其他
										$group_other1[count($group_other1)] = $row4;
									}
								}
								$group_all = array_merge($group1, $group2, $group3, $group4, $group_other1);
								//print_r($group_all);
								echo "<li id=\"phtml_1\"  leaf=\"" . $row3['level'] . "\" n_id=\"" . $row3['id'] . "\"><a href=\"" . $row3['url'] . "\">" . $row3['name'] . "</a>";
								echo '<ul>';
								for($i = 0; $i < count($group_all); $i++){
									echo "<li id=\"phtml_1\"  leaf=\"" . $group_all[$i]['level'] . "\" n_id=\"" . $group_all[$i]['id'] . "\"><a href=\"" . $group_all[$i]['url'] . "\">" . $group_all[$i]['name'] . "</a>";
										
										echo "<ul>";
										$sql5 = "select * from menu where p_id = " . $group_all[$i]['id'] . " order by id";
										$result5 = mysql_db_query($mysql_database, $sql5, $conn);
										while ($row5 = mysql_fetch_array($result5)) {
											echo "<li id='phtml_1'  leaf=\"" . $row5['level'] . "\" n_id=\"" . $row5['id'] . "\"><a href=\"" . $row5['url'] . "\"  target='main' >" . $row5['name'] . "</a>";

											echo '</li>';
										}
										echo '</ul>';
										echo '</li>';
								}
								echo '</ul>';
								echo '</li>';
								
							}else{
								echo "<li id=\"phtml_1\"  leaf=\"" . $row3['level'] . "\" n_id=\"" . $row3['id'] . "\"><a href=\"" . $row3['url'] . "\">" . $row3['name'] . "</a>";
								echo '<ul>';
								$sql4 = "select * from menu where p_id = " . $row3['id'] . " order by id";
								$result4 = mysql_db_query($mysql_database, $sql4, $conn);
								while ($row4 = mysql_fetch_array($result4)) {
									//if($row4['name'] == '线路保护'){
										
									//}else{
										echo "<li id=\"phtml_1\"  leaf=\"" . $row4['level'] . "\" n_id=\"" . $row4['id'] . "\"><a href=\"" . $row4['url'] . "\">" . $row4['name'] . "</a>";
										
										echo "<ul>";
										$sql5 = "select * from menu where p_id = " . $row4['id'] . " order by id";
										$result5 = mysql_db_query($mysql_database, $sql5, $conn);
										while ($row5 = mysql_fetch_array($result5)) {
											echo "<li id='phtml_1'  leaf=\"" . $row5['level'] . "\" n_id=\"" . $row5['id'] . "\"><a href=\"" . $row5['url'] . "\"  target='main' >" . $row5['name'] . "</a>";

											echo '</li>';
										}
										echo '</ul>';
										echo '</li>';
									//}
									
								}
								echo '</ul>';
								echo '</li>';
							}
                        }
                        echo '</ul>';
                        echo '</li>';
                    }

                    echo '</ul>';
                    echo '</li>';
                    //echo "<li id=\"phtml_1\" n_id=\"" . $row['id'] . "\"><a href=\"#\">" . $row['name'] . "</a></li>";
                }
                mysql_free_result($result1);
// 关闭连接
                mysql_close($conn);
                ?>
            </ul>
        </div>      
    </body>
</html>

 

 

  • 大小: 761.5 KB
分享到:
评论
发表评论

文章已被作者锁定,不允许评论。

相关推荐

    jQuery File Tree使用笔记

    在使用jQuery File Tree时,首先你需要在你的项目中引入jQuery库以及该插件的JavaScript文件,即`jqueryFileTree.js`。在HTML页面中,通常会有一个空的容器元素来承载文件树结构,例如: ```html &lt;div id="filetree...

    ext tree json 例子(不含EXT包)

    在本例中,我们将探讨EXT JS Tree与JSON数据的结合使用,以及如何在不依赖EXT包的情况下实现这些功能。 "ext tree json 例子(不含EXT包)"这个标题暗示我们将讨论如何在不直接引用EXT完整包的情况下,仅使用EXT JS...

    Vue2+Vue3笔记(黑马程序员+尚硅谷)

    学习Vue2+Vue3笔记可以帮助开发者全面掌握Vue.js的两种主要版本,理解它们的异同,以及如何在实际项目中选择合适的版本。黑马程序员和尚硅谷是知名的在线教育平台,它们提供的笔记内容通常覆盖了基础概念、实战案例...

    ExtJS4中文教程2 开发笔记 chm

    Edit Grid限制编辑 ExtJS 4 DirectStore post参数的变化以及应对方法 ...js函数match、exec、test、search、replace、split使用介绍 技巧:Javascript使用隐藏的new来创建对象 禁止页面全选复制,兼容多种浏览器

    Ext学习笔记

    Ext JS4学习教程+笔记(一) Ext JS4学习教程+笔记(二)事件处理 ...Ext JS4学习教程+笔记(七)树面板Tree Panel Ext JS4学习教程+笔记(三)Ajax请求 Ext JS4学习教程+笔记(五)Form Panel的使用 Ext学习网址

    ExtJS使用笔记

    ExtJS是一个开源的JavaScript库,主要用于...通过本笔记的学习,可以掌握ExtJS在前端开发中的应用,理解各个组件和管理器的使用方法,以及一些针对特定浏览器的布局技巧,为创建美观、高效的用户界面打下坚实的基础。

    dtree.js js树

    3. `新建 文本文档.txt`: 这是一个文本文件,可能是开发过程中的一些笔记或者示例代码,但不直接与`dtree.js` 的功能有关。通常可以忽略此文件,除非你在压缩包中找到了与之相关的说明。 4. `img`: 这个目录可能...

    3rdParty-jsTree:3rd Party和AngularJS演示的示例仓库

    Angular + Webpack入门(ES6) 如何运行: 克隆项目 运行npm install 运行npm start ...笔记! 如果您想将其用于生产,请注意,当前webpack会将您的源代码与供应商代码捆绑在一起。 将来会修复。

    尚硅谷vue3的学习笔记

    9. **Tree-shaking**:Vue3支持tree-shaking,这意味着未使用的组件和指令可以在构建过程中被移除,进一步减小了生产环境的代码体积。 10. **更好的错误和警告**:Vue3提供了更详细的错误和警告信息,帮助开发者更...

    AjaxTree.rar

    `51aspx源码必读.txt`可能是一个阅读指南或开发者笔记,提供了关于如何理解和使用51aspx网站上的源码的提示和建议,这可能对深入理解AjaxTree的实现有所帮助。 `最新Asp.Net源码下载.url`是一个网址链接,指向更多...

    vue-notes:vue.js原理相关笔记

    此外,Vue CLI工具集还可以帮助我们进行代码分割、Tree Shaking和Babel优化,进一步提升应用的加载速度和运行效率。 总的来说,Vue.js通过其独特的设计和强大的功能,为开发者提供了构建复杂Web应用的高效解决方案...

    jt04日常笔记

    **商品分类树**是项目04中的一项重要功能,主要使用了EasyUI.tree组件实现。该组件提供了丰富的前端展示效果,支持异步加载数据等功能。为了实现这一功能,需要在页面中引入必要的JavaScript与CSS文件,并确保在页面...

    VUE进阶 笔记贰章 前端工程化

    在前端开发领域,Vue.js已经成为了非常流行和广泛使用的JavaScript框架之一。Vue进阶笔记的第二章主要聚焦于前端工程化,这是一个旨在提高开发效率、优化代码质量和维护性的主题。前端工程化的概念涵盖了许多方面,...

    java 学习笔记

    Java学习笔记主要涵盖Java编程语言的基础知识、工具的使用以及框架的应用。在本文中,我们将深入探讨Java开发环境的配置,特别是与Eclipse和MyEclipse集成的ExtJS开发插件,以及ExtJS框架的一些常见操作和问题解决。...

    由 simple-uploader.js 提供支持的 Vue.js 上传组件.zip

    由 simple-uploader.js 提供支持的 Vue.js 上传组件vue-simple-uploader 由simple-uploader.js提供支持的 Vue.js 上传组件使用 vue 3English 中文特征将文件夹和文件视为File暂停/恢复上传恢复上传错误处理使用...

    Xpage学习笔记

    #### 2.5.4 在 Xpage 中使用树(dijit.Tree) - **JSON 与 XML 数据源**:可以用 JSON 或 XML 文件作为数据源。 - **Box 树与 Order 树**:展示不同结构的树形数据。 - **对树进行添加、删除及重命名操作**:可以直接...

    笔记本:我的笔记本:ledger:

    基于以上信息,我们可以推测这是一个使用Vue.js和CSS构建的个人笔记本应用,具有良好的跨平台兼容性,支持触屏交互和滚动效果。项目中可能使用了树形结构来组织笔记,BFC可能在解决布局问题上起到了作用。用户可以在...

    godbasin.github.io:被删除的前端博客-喜欢请star

    D3.js-Tree实战笔记 Vue2笔记 纯前端的进军 Cycle.js笔记 webpack多页面配置 非科班恶补算法 无角2 Angular2相关 Webpack相关 前端阶段性总结 CSS相关 js相关 jQuery相关 three.js笔记

    对初学者有帮助的Ext笔记

    8. JavaScript日期操作:`new Date().add(Date.DAY, -1)`是自定义的方法,通常用于将当前日期减去一天,但标准JavaScript中并没有`add`方法,实际使用时需要引用特定库,如`date.js`。 9. ExtJS中的ComboBox:这是...

    vue第五天笔记04——打包

    6. **优化**:Webpack提供了多种优化策略,包括代码分割(将大型组件或第三方库异步加载)、Tree Shaking(移除未使用的代码)、Minification(压缩代码)和Hashed Module IDs(使用文件内容哈希作为模块ID,防止...

Global site tag (gtag.js) - Google Analytics