Jquery tree plug in zTree implements menu tree

  • 2021-07-15 03:42:12
  • OfStack

This article example for everyone to share the zTree plug-in menu tree specific code, for your reference, the specific content is as follows


<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>Title</title>
    <link href="JS/tool/zTree/css/zTreeStyle/zTreeStyle.css" rel="stylesheet" />
    <script src="JS/jquery-1.11.1.min.js"></script>
    <script src="JS/tool/zTree/js/jquery.ztree.core-3.5.js"></script>
    <script src="JS/tool/zTree/js/jquery.ztree.excheck-3.5.js"></script>

</head>
<body style="background: #ddd;">
    <div class="mainbody-left">
          <div class="vvtree dept-tree left">
                <ul id="menu_tree_left" class="ztree"></ul>
          </div>
    </div>
    <script>
          var settingLeft = {
                view: {
                      dblClickExpand: false,// Whether the identity of the parent node is automatically expanded when the node is double-clicked 
                      showLine: false,// Display connections between nodes 
                      showIcon: true,
                      fontCss: { 'color': 'white', 'font-weight': 'normal' },// Font style function 
                      selectedMulti: false // Set whether multiple nodes are allowed to be selected at the same time 
                },
                check: {
                      //chkboxType: { "Y": "ps", "N": "ps" },
                      chkStyle: "checkbox",// Check box type 
                      enable: false // Is displayed on each node  CheckBox
                },
                data: {
                      simpleData: {// Simple data schema 
                            enable: true,
                            idKey: "id",
                            pIdKey: "pId",
                            rootPId: ""
                      }
                },
                callback: {

                      beforeClick: function (treeId, treeNode) {
                            zTree = $.fn.zTree.getZTreeObj("menu_tree_vehicle");
                            if (treeNode.isParent) {
                                  zTree.expandNode(treeNode);// If it is a parent node, expand the node 
                            } else {
                                  zTree.checkNode(treeNode, !treeNode.checked, true, true);// Click to check, and then click to uncheck again 
                            }
                      }//,
                      // onCheck: onCheck

                }
          };

          $(function () {
                // Initialize menu tree 
                var zNodes = [
                      { id: 0, pId: -1, name: "1 Level department ", open: true },
                      { id: 1, pId: 0, name: "2 Level department 1", open: false },
                      { id: 2, pId: 1, name: "3 Level department 1" },
                      { id: 3, pId: 1, name: "3 Level department 2" },
                      { id: 4, pId: 0, name: "2 Level department 2", open: false },
                      { id: 5, pId: 4, name: "3 Level department 3" },
                      { id: 6, pId: 4, name: "3 Level department 4", open: false },
                      { id: 7, pId: 6, name: "4 Level department 1" },
                      { id: 8, pId: 6, name: "4 Level department 2" },
                      { id: 9, pId: 0, name: "2 Level department 3" },
                      { id: 10, pId: 0, name: "2 Level department 4" }
                ];
                $.fn.zTree.init($("#menu_tree_left"), settingLeft, zNodes);
          });
    </script>
</body>

</html>

For more information on ztree controls, refer to the topic "jQuery plug-in ztree usage summary."


Related articles: