首頁  >  文章  >  web前端  >  EasyUI結合zTree樹形結構製作網頁

EasyUI結合zTree樹形結構製作網頁

php中世界最好的语言
php中世界最好的语言原創
2018-04-19 15:45:301545瀏覽

這次帶給大家EasyUI結合zTree樹狀結構製作網頁,EasyUI結合zTree樹狀結構製作網頁的注意事項有哪些,以下就是實戰案例,一起來看一下。

JQuery EasyUI 結合 zTree樹形結構製作web頁面.easyui用起來比較簡單,很好的封裝了jquery的部分功能,使用起來更加方便,但是從1.2.3版本以後,商業用途是需要付費的,zTree是國內的大牛們搞的一個jquery樹形tree外掛,感覺很好用,很強大,而且完全免費,API等做的也非常不錯.推薦

# easyui 是一個基於 jQuery 的框架,整合了各種使用者介面插件。

easyui 提供建立現代化的具有互動性的 javascript 應用的必要的功能。

使用 easyui,您不需要寫太多 javascript 程式碼,一般情況下您只需要使用一些 html 標記來定義使用者介面。

HTML 網頁的完整框架。

easyui 節省了開發產品的時間和規模。

easyui 非常簡單,但功能非常強大。

需要的導入以下幾種js檔案和樣式表

# easyui/themes/default/easyui.css
easyui/themes/icon.css  
jquery-1.8.3.js
easyui/jquery.easyui.min.js
ztree/jquery.ztree. all-3.5.js(該檔案包括core,exhide,exedit,excheck)
ztree/zTreeStyle.css

<script type="text/javascript">  
 // ztree菜单设置
 varzTreeObj,
 setting = {
  view: {
   selectedMulti:false
  },
  // 添加编辑设置:修改树节点名称/删除树节点
  edit: {
   enable:true
  },
  data: {
   simpleData: {
    enable:true
   }
  },
  callback:{
   onClick: zTreeOnClick
  }
 };
  
 // 回调函数:单击事件
 functionzTreeOnClick(event, treeId, treeNode, clickFlag) {
  alert(treeNode.id +", "+ treeNode.name);
  varcontent ='<p style="width:100%;height:100% ;overflow:hidden;">'
       +'<iframe src="&#39;
       +treeNode.url
       +&#39;" scrolling="auto" style="width:100%;height:100%;border:0;"></iframe></p>';
  if(treeNode.url != undefined && treeNode.url !=""){
   // 当centre中是否存在名称为treeNode.name的tabs
   if($("#tt").tabs('exists',treeNode.name)){
    $("#tt").tabs('select',treeNode.name);
   }else{
    $("#tt").tabs('add',{
     title:treeNode.name,
     content:content,
     closable:true
    })
   }
  };
  event.preventDefault();
 };
  
 // 提供ztree树形菜单数据
 zTreeNodes = [ {"id":1,"pId":0,"name":"海贼王"},
        {"id":11,"pId":1,"name":"娜美","url":"http://man.linuxde.net/"},
        {"id":12,"pId":1,"name":"罗宾","url":"http://www.baidu.com"},
        {"id":13,"pId":1,"name":"汉库克","url":"http://www.google.cn/"},
        {"id":2,"pId":0,"name":"父节点 2","open":true},
        {"id":21,"pId":2,"name":"叶子节点 2-1"},
        {"id":22,"pId":2,"name":"叶子节点 2-2"},
        {"id":23,"pId":2,"name":"叶子节点 2-3"},
        {"id":3,"pId":0,"name":"父节点 3","open":true},
        {"id":31,"pId":3,"name":"叶子节点 3-1"},
        {"id":32,"pId":3,"name":"叶子节点 3-2"},
        {"id":33,"pId":3,"name":"叶子节点 3-3"}
       ];
  
 // 3.生成树形菜单
 $(document).ready(function(){
  zTreeObj = $.fn.zTree.init($("#tree"), setting, zTreeNodes);
 });
  
 // 4.对象选项卡注册右击事件
 $(document).ready(function(){
  $("#tt").tabs({
   onContextMenu:function(e,title,index){
   // 阻止系统默认的右击事件
    e.preventDefault();
    $('#mm').menu('show', {
     left: e.pageX,
     top: e.pageY
    });
   }
  });
 });
  
 // 获取所选取的面板对象
 $(document).ready(function(){
  $("#tt").tabs({
   // 获取所选取的面板对象
   onSelect :function(title,index ){
    // 5. menu的单击事件绑定
    $("#mm").menu({
     onClick:function(item){
      alert(item.name);
      // 当点击关闭当前选项卡时
      if(item.name==='current'){
       $('#tt').tabs('close',title);
      // 当点击关闭其他选项卡时
      }elseif(item.name ==='others'){
       vartabs = $('#tt').tabs('tabs');
       $(tabs).each(function(){
        if($(this).panel('options').title !='消息中心'&& $(this).panel('options').title != title){
         $('#tt').tabs('close',$(this).panel('options').title);
        }
       });
      // 当点击关闭所有选项卡时
      }elseif(item.name ==='all'){
       vartabs = $('#tt').tabs('tabs');
       $(tabs).each(function(){
          if($(this).panel('options').title !='消息中心'){
         $('#tt').tabs('close',$(this).panel('options').title);
        }
       });
      }
     }
    });
   }
  })
 })
</script>

# 對應的htm 部分程式碼

<bodyclass="easyui-layout">
 <pdata-options="region:&#39;north&#39;,title:&#39;北丐:洪七公&#39;,split:true"style="height:100px;"></p>
 <pdata-options="region:&#39;south&#39;,title:&#39;南帝:一灯大师&#39;,split:true"style="height:100px;"></p>
 <pdata-options="region:&#39;east&#39;,iconCls:&#39;icon-reload&#39;,title:&#39;东邪:黄药师&#39;,split:true"style="width:100px;"></p>
 <pdata-options="region:&#39;west&#39;,title:&#39;西毒:欧阳锋&#39;,split:true"style="width:250px;">
  <pid="aa"data-options="fit:&#39;true&#39;"class="easyui-accordion">
   <ptitle="赵敏"data-options="iconCls:&#39;icon-save&#39;">
    <h3style="color:#0099FF;">Accordion for jQuery</h3>
    <p>Accordion is a part of easyui framework for jQuery. It lets you define your accordion component on web page more easily.</p>
   </p>
   <ptitle="大玉儿"data-options="iconCls:&#39;icon-reload&#39;,selected:true">
    // ztree属性结构
    <ulid="tree"class="ztree"style="width:230px; overflow:auto;"></ul>
   </p>
   <ptitle="婉容儿">
    who?
   </p>
  </p>
 </p>
 <pdata-options="region:&#39;center&#39;,title:&#39;中神通:周伯通&#39;">
  // tabs 面板
  <pid="tt"class="easyui-tabs"data-options="fit:true">
   <ptitle="小龙女"data-options="closable:true"></p>
   <ptitle="沐剑屏"data-options="closable:true"></p>
   <ptitle="阿珂"data-options="iconCls:&#39;icon-reload&#39;,closable:true"></p>
  </p>
 </p>
  
 // menu菜单栏
 <pid="mm"class="easyui-menu"style="width:120px;">
  <pname="current">关闭当前选项卡</p>
  <pname="others">关闭其他选项卡</p>
  <pclass="menu-sep"></p>
  <pdata-options="iconCls:&#39;icon-cancle&#39;"name="all">关闭所有选项卡</p>
 </p>
</body>

相信看了本文案例你已經掌握了方法,更多精彩請關注php中文網其它相關文章!

推薦閱讀:

jQuery做出滑鼠滾輪動作圖片縮放小

在jquery怎麼使用鍵盤事件

以上是EasyUI結合zTree樹形結構製作網頁的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn