欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JQuery ZTree使用方法詳解

 更新時(shí)間:2017年01月07日 09:55:47   作者:Switch_vov  
這篇文章主要為大家詳細(xì)介紹了JQuery ZTree使用方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

JQuery ZTree簡(jiǎn)單使用

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

基本概述

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

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

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

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

案例

使用標(biāo)準(zhǔn)json數(shù)據(jù)構(gòu)造ztree

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
  <head>
   <meta charset="UTF-8">
   <title>ztree測(cè)試</title>
   <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/js/easyui/themes/default/easyui.css">
   <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/js/easyui/themes/icon.css">
   <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.8.3.js"></script>
   <script type="text/javascript" src="${pageContext.request.contextPath}/js/easyui/jquery.easyui.min.js"></script>
   <link rel="stylesheet" href="${pageContext.request.contextPath}/js/ztree/zTreeStyle.css" type="text/css">
   <script type="text/javascript" src="${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", "標(biāo)題");
      if(isExists) {
        $("#et").tabs("select","標(biāo)題");
      } else {
        $("#et").tabs("add", {
         title:"標(biāo)題",
         closable:true,
         iconCls:"icon-save",
         content:"<iframe frameborder='no' height='100%' width='100%' src='3-tabs.jsp'></iframe>"
        });
      }
     });
    });
   </script>
   <!-- 使用標(biāo)準(zhǔn)json數(shù)據(jù)構(gòu)造ztree -->
   <script type="text/javascript">
    $(function() {
     var setting = {};

     var zNodes = [
         {name:'結(jié)點(diǎn)1',children:[
              {name:'結(jié)點(diǎn)11'},
              {name:'結(jié)點(diǎn)12'}
              ]},
         {name:'結(jié)點(diǎn)2'},
         {name:'結(jié)點(diǎn)3'}
         ];

     $.fn.zTree.init($("#ztree1"), setting, zNodes);
    });
   </script>
  </head>
  <body class="easyui-layout">
   <!-- 分為五個(gè)區(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è)務(wù)菜單">
      <ul id="ztree1" class="ztree"></ul>
     </div>
     <div data-options="iconCls:'icon-remove'" title="功能菜單">內(nèi)容3</div>
     <div data-options="iconCls:'icon-remove'" title="非功能菜單">內(nèi)容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)菜單">內(nèi)容1</div>
     <div data-options="iconCls:'icon-remove'" title="業(yè)務(wù)菜單">內(nèi)容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>

使用簡(jiǎn)單json數(shù)據(jù)構(gòu)造ztree

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

 <!-- 使用簡(jiǎn)單json數(shù)據(jù)構(gòu)造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請(qǐng)求獲取動(dòng)態(tài)json數(shù)據(jù)構(gòu)造ztree

json內(nèi)容

[
  { "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請(qǐng)求獲取動(dòng)態(tài)json數(shù)據(jù)構(gòu)造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é)點(diǎn)綁定事件動(dòng)態(tài)添加選項(xiàng)卡

json內(nèi)容

[
  { "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é)點(diǎn)綁定事件動(dòng)態(tài)添加選項(xiàng)卡 -->
 <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='"+ 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>

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • jQuery+HTML5加入購物車代碼分享

    jQuery+HTML5加入購物車代碼分享

    這篇文章主要為大家詳細(xì)介紹了jQuery+HTML5加入購物車的實(shí)現(xiàn)代碼,功能很齊全,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2015-08-08
  • jQuery實(shí)現(xiàn)菜單顯示效果

    jQuery實(shí)現(xiàn)菜單顯示效果

    這篇文章主要為大家詳細(xì)介紹了jQuery實(shí)現(xiàn)菜單顯示效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-12-12
  • jquery中:input和input的區(qū)別分析

    jquery中:input和input的區(qū)別分析

    :input表示選擇表單中的input,select,textarea,button元素,input僅僅選擇input元素。
    2011-07-07
  • JQuery jsonp 使用示例代碼

    JQuery jsonp 使用示例代碼

    JQuery jsonp 使用示例,想學(xué)習(xí)的朋友可以參考下。
    2009-08-08
  • Jquery 獲取相同NAME 或者id刪除行操作

    Jquery 獲取相同NAME 或者id刪除行操作

    這篇文章主要介紹了Jquery 獲取相同NAME 或者id刪除行操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-08-08
  • jQuery中dequeue()方法用法實(shí)例

    jQuery中dequeue()方法用法實(shí)例

    這篇文章主要介紹了jQuery中dequeue()方法用法,實(shí)例分析了dequeue()方法的功能、定義、使用技巧與相關(guān)注意事項(xiàng),具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2014-12-12
  • 基于hover的用法實(shí)例(推薦)

    基于hover的用法實(shí)例(推薦)

    下面小編就為大家?guī)硪黄趆over的用法實(shí)例(推薦)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-07-07
  • SelecT下拉框選中和取值的解決方法

    SelecT下拉框選中和取值的解決方法

    Select下拉框的問題,想在選擇一個(gè)選項(xiàng)后,前臺(tái)顯示做出變動(dòng),并且知道選擇的是第幾個(gè)選項(xiàng)。怎么解決這個(gè)問題呢?下面小編給大家分享SelecT下拉框選中和取值的解決方法,需要的朋友參考下吧
    2016-11-11
  • ASP.NET中AJAX 調(diào)用實(shí)例代碼

    ASP.NET中AJAX 調(diào)用實(shí)例代碼

    最近在ASP.NET中做了一個(gè)AJAX調(diào)用 : Client端先從ASP.NET Server后臺(tái)取到一個(gè)頁面模板,然后在頁面初始化時(shí)再從Server中取一些相關(guān)數(shù)據(jù)以實(shí)現(xiàn)頁面模板的動(dòng)態(tài)顯示
    2012-05-05
  • 十個(gè)迅速提升JQuery性能讓你的JQuery跑得更快

    十個(gè)迅速提升JQuery性能讓你的JQuery跑得更快

    jQuery正在成為Web開發(fā)人員首選的JavaScript庫,作為Web開發(fā)者,除了要了解語言和框架的應(yīng)用技巧外如何提升語言的性能,本文提供即刻提升你的腳本性能的十個(gè)步驟 簡(jiǎn)單的幾步讓你的JQuery跑得更快 需要的朋友可以參考下
    2012-12-12

最新評(píng)論