zoukankan      html  css  js  c++  java
  • 通过后台定义获取顶级节点

    <!DOCTYPE html>
    <HTML>
    <HEAD>
    <TITLE> ZTREE DEMO - select menu</TITLE>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <link rel="stylesheet" href="../../../css/demo.css" type="text/css">
    <link rel="stylesheet" href="../../../css/zTreeStyle/zTreeStyle.css" type="text/css">
    <script type="text/javascript" src="../../../js/jquery-1.4.4.min.js"></script>
    <script type="text/javascript" src="../../../js/jquery.ztree.core.js"></script>
    <script type="text/javascript" src="../../../js/jquery.ztree.excheck.js"></script>
    <script type="text/javascript" src="../../../js/jquery.ztree.exedit.js"></script>
    <SCRIPT type="text/javascript">
    <!--
    var setting = {
    view: {
    dblClickExpand: false
    },
    check: {
    enable: true
    },
    callback: {
    onRightClick: OnRightClick
    }
    };

    var zNodes =[
    {id:1, name:"无右键菜单 1", open:true, noR:true,
    children:[
    {id:11, name:"节点 1-1", noR:true},
    {id:12, name:"节点 1-2", noR:true}

    ]},
    {id:2, name:"右键操作 2", open:true,
    children:[
    {id:21, name:"节点 2-1"},
    {id:22, name:"节点 2-2"},
    {id:23, name:"节点 2-3"},
    {id:24, name:"节点 2-4"}
    ]},
    {id:3, name:"右键操作 3", open:true,
    children:[
    {id:31, name:"节点 3-1"},
    {id:32, name:"节点 3-2"},
    {id:33, name:"节点 3-3"},
    {id:34, name:"节点 3-4"}
    ]}
    ];

    /*function OnRightClick(event, treeId, treeNode) {
    var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
    var sNodes = treeObj.getSelectedNodes();

    if (sNodes.length > 0) {
    var parentTId = sNodes[0].parentTId;
    if(parentTId==null){
    showRMenu();
    }

    }

    }
    */
    function OnRightClick(event, treeId, treeNode) {
    var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
    var sNodes = treeObj.getSelectedNodes();

    if (sNodes.length > 0) {
    var parentTId = sNodes[0].parentTId;
    //我门后台人员把所有的顶级节点设置id为0;这样轻而易举就可以拿到顶层节点了
    if(treeNode.pid==0){
    showRMenu();
    }

    }

    }
    function showRMenu(event) {
    var e = event || window.event;
    var scrollX = document.documentElement.scrollLeft || document.body.scrollLeft;
    var scrollY = document.documentElement.scrollTop || document.body.scrollTop;
    var x = e.pageX || e.clientX + scrollX;
    var y = e.pageY || e.clientY + scrollY;
    rMenu.css({"top":y+"px", "left":x+"px", "visibility":"visible"});
    $("body").bind("mousedown", onBodyMouseDown);
    }

    function onBodyMouseDown(event){
    if (!(event.target.id == "rMenu" || $(event.target).parents("#rMenu").length>0)) {
    rMenu.css({"visibility" : "hidden"});
    }
    }
    function shoucang() {

    }

    $(document).ready(function(){
    $.fn.zTree.init($("#treeDemo"), setting, zNodes);
    zTree = $.fn.zTree.getZTreeObj("treeDemo");
    rMenu = $("#rMenu");
    });
    //-->
    </SCRIPT>
    <style type="text/css">
    div#rMenu {position:absolute; visibility:hidden; top:0; background-color: #555;text-align: left;padding: 2px;}
    div#rMenu ul li{
    margin: 1px 0;
    padding: 0 5px;
    cursor: pointer;
    list-style: none outside none;
    background-color: #DFDFDF;
    }
    </style>
    </HEAD>

    <BODY>


    <ul id="treeDemo" class="ztree"></ul>

    <div id="rMenu">
    <ul>
    <li id="m_add" onclick="shoucang();">收藏</li>
    </ul>
    </div>
    </BODY>
    </HTML>

  • 相关阅读:
    学好VC++的十大良好习惯
    VC6.0调试技巧
    匈牙利命名法
    VC中常用文件操作(三)
    VL_FEAT——图像处理函数库
    MATLAB——linspace
    (Your)((Term)((Project)))(字符串处理)
    Matrix Chain Multiplication(栈的简单应用)
    The Triangle(DP基础)
    MATLAB——polyfit
  • 原文地址:https://www.cnblogs.com/lppswkf/p/7877745.html
Copyright © 2011-2022 走看看