zTree树形菜单交互选项卡效果实现

1、 添加自定义属性 page 
2、 为 ztree 每个树形节点,添加点击事件

 1 <!DOCTYPE html>
 2 <html>
 3 
 4     <head>
 5         <meta charset="UTF-8">
 6         <title>ztree树形菜单的使用</title>
 7         <!-- 导入jquery核心类库 -->
 8         <script type="text/javascript" src="../js/jquery-1.8.3.js"></script>
 9         <!-- 导入easyui类库 -->
10         <link id="easyuiTheme" rel="stylesheet" type="text/css" href="../js/easyui/themes/default/easyui.css">
11         <link rel="stylesheet" type="text/css" href="../js/easyui/themes/icon.css">
12         <link rel="stylesheet" type="text/css" href="../css/default.css">
13         <script type="text/javascript" src="../js/easyui/jquery.easyui.min.js"></script>
14         <!--引入ztree-->
15         <script src="../js/ztree/jquery.ztree.all-3.5.js" type="text/javascript" charset="utf-8"></script>
16         <link rel="stylesheet" type="text/css" href="../js/ztree/zTreeStyle.css" />
17 
18         <script type="text/javascript">
19             //页面加载后执行
20             $(function() {
21                 //1.进行ztree树形菜单设置,开启简单json数据支持
22                 var setting = {
23                     data:{
24                         simpleData:{
25                             enable:true//开启简单json数据格式支持
26                         }
27                     },
28                     callback:{
29                         onClick:function(event,treeId,treeNode,clickFlag){
30                             var content = '<div style="width:100%;height:100%;overflow:hidden;">'+'<iframe src="'+treeNode.page+'" scrolling="auto" style="width:100%;height:100%;border:0;"></iframe></div>'
31                             //没有设置page属性的树形菜单,不打开选项卡
32                             if(treeNode.page!=undefined && treeNode.page!=""){
33                                 //如果选项卡已经打开,就选中
34                                 if($("#mytabs").tabs('exists',treeNode.name)){
35                                     //选中选项卡
36                                     $("#mytabs").tabs('select',treeNode.name);
37                                 }else{
38                                     //如果没有打开,添加选项卡
39                                     $("#mytabs").tabs('add',{
40                                         title:treeNode.name,
41                                         content:content,
42                                         closable:true
43                                     });
44                                 }
45                             }
46                         }
47                     }
48                 };
49 
50                 //2.提供ztree树形菜单数据
51                 var zNodes = [
52                     {id:1,pId:0,name:"父节点一"},
53                     {id:2,pId:0,name:"父节点二"},
54                     {id:11,pId:1,name:"子节点一"},
55                     {id:12,pId:1,name:"子节点二"},
56                     {id:13,pId:2,name:"CSDN博客",page:"http://blog.csdn.net/a772304419"},
57                     {id:14,pId:2,name:"博客园",page:"http://www.cnblogs.com/niwotaxuexiba/"}
58                 ];
59 
60                 //3.生成树形菜单
61                 $.fn.zTree.init($("#baseMenu"),setting,zNodes);
62             });
63         </script>
64     </head>
65 
66     <body class="easyui-layout">
67         <div data-options="region:'north',title:'你我他学习吧-学习Java的好博客!'" style="height:100px"></div>
68         <div data-options="region:'west',title:'菜单导航'" style="width:200px">
69             <!--折叠面板-->
70             <div class="easyui-accordion" data-options="fit:true">
71                 <div data-options="title:'基础菜单'">
72                     <!--通过ztree插件,制作树形菜单-->
73                     <ul id="baseMenu" class="ztree"></ul>
74                 </div>
75                 <div data-options="title:'系统菜单'">你我他学习吧</div>
76             </div>
77         </div>
78         <div data-options="region:'center',title:'中部区域'">
79             <!--选项卡面板-->
80             <div id="mytabs" class="easyui-tabs" data-options="fit:true">
81                 <div data-options="title:'选项卡面板一',closable:true">选项卡面板一</div>
82                 <div data-options="title:'选项卡面板二',closable:true">选项卡面板二</div>
83             </div>
84         </div>
85         <div data-options="region:'east',title:'东部区域'" style="width:100px"></div>
86         <div data-options="region:'south',title:'南部区域'" style="height:100px"></div>
87     </body>
88 
89 </html>

 

posted @ 2017-12-24 21:46  学亮编程手记  阅读(1531)  评论(0编辑  收藏  举报