成人精品一区二区三区中文字幕-成人精品一区二区三区-成人精品一级毛片-成人精品亚洲-日本在线视频一区二区-日本在线视频免费

導航首頁 ? 技術教程 ? JQuery ZTree使用方法詳解
全站頭部文字 我要出現(xiàn)在這里
JQuery ZTree使用方法詳解 719 2024-02-06   

JQuery ZTree簡單使用

@(JavaScript)[jQuery, ztree, 入門]

基本概述

zTree 是一個依靠 jQuery 實現(xiàn)的多功能 “樹插件”。優(yōu)異的性能、靈活的配置、多種功能的組合是 zTree 最大優(yōu)點。專門適合項目開發(fā),尤其是 樹狀菜單、樹狀數(shù)據(jù)的Web顯示、權限管理等等。

zTree 是開源免費的軟件(MIT 許可證)。在開源的作用下,zTree 越來越完善,目前已經(jīng)擁有了不少粉絲,并且今后還會推出更多的 zTree 擴展功能庫,讓 zTree 更加強大。 ——參考《百度百科》

官網(wǎng):zTree官網(wǎng)

PS:zTree的官方API文檔和demo挺詳細的,值得一讀。

案例

使用標準json數(shù)據(jù)構造ztree

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
  <head>
   <meta charset="UTF-8">
   <title>ztree測試</title>
   <link rel="stylesheet" type="text/css" >
   <link rel="stylesheet" type="text/css" >
   <script type="text/javascript" src="http://www.gimoo.net/t/1808/${pageContext.request.contextPath}/js/jquery-1.8.3.js"></script>
   <script type="text/javascript" src="http://www.gimoo.net/t/1808/${pageContext.request.contextPath}/js/easyui/jquery.easyui.min.js"></script>
   <link rel="stylesheet"  type="text/css">
   <script type="text/javascript" src="http://www.gimoo.net/t/1808/${pageContext.request.contextPath}/js/ztree/jquery.ztree.all-3.5.js"></script>

   <script type="text/javascript">
    $(function(){
     $("#btn").click(function() {
      var isExists = $("#et").tabs("exists", "標題");
      if(isExists) {
        $("#et").tabs("select","標題");
      } else {
        $("#et").tabs("add", {
         title:"標題",
         closable:true,
         iconCls:"icon-save",
         content:"<iframe frameborder='no' height='100%' width='100%' src='http://www.gimoo.net/t/1808/3-tabs.jsp'></iframe>"
        });
      }
     });
    });
   </script>
   < 使用標準json數(shù)據(jù)構造ztree -->
   <script type="text/javascript">
    $(function() {
     var setting = {};

     var zNodes = [
         {name:'結點1',children:[
              {name:'結點11'},
              {name:'結點12'}
              ]},
         {name:'結點2'},
         {name:'結點3'}
         ];

     $.fn.zTree.init($("#ztree1"), setting, zNodes);
    });
   </script>
  </head>
  <body class="easyui-layout">
   < 分為五個區(qū)域 -->
   <div style="height: 100px;" data-options="region:'north'">北部區(qū)域</div>
   <div style="width: 200px;" data-options="region:'west'">
    <div class="easyui-accordion" data-options="fit:true">
     <div data-options="iconCls:'icon-save'" title="系統(tǒng)菜單">
      <a id="btn" class="easyui-linkbutton">按鈕</a>
     </div>
     <div data-options="iconCls:'icon-remove'" title="業(yè)務菜單">
      <ul id="ztree1" class="ztree"></ul>
     </div>
     <div data-options="iconCls:'icon-remove'" title="功能菜單">內容3</div>
     <div data-options="iconCls:'icon-remove'" title="非功能菜單">內容4</div>
    </div>
   </div>
   <div style="" data-options="region:'center'">
    <div id="et" class="easyui-tabs" data-options="fit:true">
     <div data-options="iconCls:'icon-save', closable:true" title="系統(tǒng)菜單">內容1</div>
     <div data-options="iconCls:'icon-remove'" title="業(yè)務菜單">內容2</div>
    </div>
   </div>
   <div style="width: 100px;" data-options="region:'east'">東部區(qū)域</div>
   <div style="height: 50px;" data-options="region:'south'">南部區(qū)域</div>
  </body>
</html>

使用簡單json數(shù)據(jù)構造ztree

   <div data-options="iconCls:'icon-remove'" title="功能菜單">
    <ul id="ztree2" class="ztree"></ul>
   </div>

 < 使用簡單json數(shù)據(jù)構造ztree -->
 <script type="text/javascript">
  $(function() {
   var setting = {
    data: {
      simpleData: {
       enable: true
      }
    }
   };

   var zNodes = [
    {"id":1, "pId":0, "name":"test1"},
    {"id":11, "pId":1, "name":"test11"},
    {"id":12, "pId":1, "name":"test12"},
    {"id":111, "pId":11, "name":"test111"},
    {"id":2, "pId":0, "name":"test2"},
    {"id":3, "pId":0, "name":"test3"},
    {"id":31, "pId":2, "name":"test31"}
   ];

   $.fn.zTree.init($("#ztree2"), setting, zNodes);
  });
 </script>

發(fā)送ajax請求獲取動態(tài)json數(shù)據(jù)構造ztree

json內容

[
  { "id":"11", "pId":"0", "name":"菜單1"},
  { "id":"111", "pId":"11", "name":"菜單11", "page":"xx.action"},
  { "id":"112", "pId":"11", "name":"菜單12","page":"xx.action"},
  { "id":"113", "pId":"11", "name":"菜單13", "page":"xx.action"},
  { "id":"114", "pId":"11", "name":"菜單14","page":"xx.action"},
  { "id":"12", "pId":"0", "name":"菜單2"},
  { "id":"121", "pId":"12", "name":"菜單21" ,"page":"xx.action"},
  { "id":"122", "pId":"12", "name":"菜單22" ,"page":"xx.action"},
  { "id":"123", "pId":"12", "name":"菜單23" ,"page":"xx.action"},
  { "id":"13", "pId":"0", "name":"菜單3"},
  { "id":"131", "pId":"13", "name":"菜單31","page":"xx.action"},
  { "id":"132", "pId":"13", "name":"菜單32","page":"xx.action"}
]

html片段

   <div data-options="iconCls:'icon-remove'" title="非功能菜單">
    <ul id="ztree3" class="ztree"></ul>
   </div>

 < 發(fā)送ajax請求獲取動態(tài)json數(shù)據(jù)構造ztree -->
 <script type="text/javascript">
  $(function() {
   var setting = {
    data: {
      simpleData: {
       enable: true
      }
    }
   };

   $.ajax({
    url:'${pageContext.request.contextPath}/json/menu.json',
    type:'get',
    data:'',
    dataType:'json',
    success:function (data) {
      $.fn.zTree.init($("#ztree3"), setting, data);
    }
   });
  });
 </script>

為ztree節(jié)點綁定事件動態(tài)添加選項卡

json內容

[
  { "id":"11", "pId":"0", "name":"菜單1"},
  { "id":"111", "pId":"11", "name":"菜單11", "page":"xx.action"},
  { "id":"112", "pId":"11", "name":"菜單12","page":"xx.action"},
  { "id":"113", "pId":"11", "name":"菜單13", "page":"xx.action"},
  { "id":"114", "pId":"11", "name":"菜單14","page":"xx.action"},
  { "id":"12", "pId":"0", "name":"菜單2"},
  { "id":"121", "pId":"12", "name":"菜單21" ,"page":"xx.action"},
  { "id":"122", "pId":"12", "name":"菜單22" ,"page":"xx.action"},
  { "id":"123", "pId":"12", "name":"菜單23" ,"page":"xx.action"},
  { "id":"13", "pId":"0", "name":"菜單3"},
  { "id":"131", "pId":"13", "name":"菜單31","page":"xx.action"},
  { "id":"132", "pId":"13", "name":"菜單32","page":"xx.action"}
]

html文件

   <div data-options="iconCls:'icon-save'" title="ztree事件">
    <ul id="ztree4" class="ztree"></ul>
   </div>

 < 為ztree節(jié)點綁定事件動態(tài)添加選項卡 -->
 <script type="text/javascript">
  $(function() {
   var setting = {
    data: {
      simpleData: {
       enable: true
      }
    },
    callback: {
      onClick: function(event, treeId, treeNode) {
       if(treeNode.page != undefined) {
        var isExists = $("#et").tabs("exists", treeNode.name);
        if(isExists) {
         $("#et").tabs("select", treeNode.name);
        } else {
         $("#et").tabs("add", {
          title:treeNode.name,
          closable:true,
          iconCls:"icon-edit",
          content:"<iframe frameborder='no' height='100%' width='100%' src='http://www.gimoo.net/t/1808/5b67d0aa13774.html"+ treeNode.page +"'></iframe>"
         });
        }
       }
      }
    }
   };

   $.ajax({
    url:'${pageContext.request.contextPath}/json/menu.json',
    type:'get',
    data:'',
    dataType:'json',
    success:function (data) {
      $.fn.zTree.init($("#ztree4"), setting, data);
    }
   });
  });
 </script>

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持綠夏網(wǎng)。



主站蜘蛛池模板: 神犬奇兵 电视剧| 拔萝卜无删减| 山海经动画片全40集免费观看| 违规吃喝心得体会100字| 林冲演员| 青春派电视剧免费完整版在线观看 | 拔萝卜视频免费播放| 奶粉罐回收多少钱一个| 三年电影| 尘埃落定演员表| 地下车库设计规范| 林丹出轨视频| 《她的城》电视剧| 吃光全宇宙| 欧美变态挠痒痒视频∨k| 妻子的秘密按摩电影| 养小动物的作文| 学生会长的忠告| 曹查理新剧《三姐妹》| bbb.| 郭云飞| 电影喜剧明星演员表| 小女巫| 晕车喝什么饮料能缓解| 东成西就| 欢乐的牧童钢琴谱| christie stevens| 我这一辈子电影| 美国伦理女兵1| 美女全身透明衣服| 古铜| 眉间尺| 爱上女老师| rima horton| 3d成人国产同人动漫焰灵姬| 女同性激烈床戏舌吻戏| 音乐会电视剧免费观看完整版 | 新上海滩张国荣和宁静| 欧美日韩欧美日韩在线观看视频| 黄老汉| 红灯停绿灯行电影观看|

!!!站長長期在線接!!!

網(wǎng)站、小程序:定制開發(fā)/二次開發(fā)/仿制開發(fā)等

各種疑難雜癥解決/定制接口/定制采集等

站長微信:lxwl520520

站長QQ:1737366103