JQuery ZTree简单使用
@(JavaScript)[jQuery, ztree, 入门]
基本概述
zTree 是一个依靠 jQuery 实现的多功能 “树插件”。优异的性能、灵活的配置、多种功能的组合是 zTree 最大优点。专门适合项目开发,尤其是 树状菜单、树状数据的Web显示、权限管理等等。
zTree 是开源免费的软件(MIT 许可证)。在开源的作用下,zTree 越来越完善,目前已经拥有了不少粉丝,并且今后还会推出更多的 zTree 扩展功能库,让 zTree 更加强大。 ——参考《百度百科》
官网:zTree官网
PS:zTree的官方API文档和demo挺详细的,值得一读。
案例
使用标准json数据构造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" 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="/UploadFiles/2021-04-02/jquery-1.8.3.js">使用简单json数据构造ztree
<div data-options="iconCls:'icon-remove'" title="功能菜单"> <ul id="ztree2" class="ztree"></ul> </div> <!-- 使用简单json数据构造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>发送ajax请求获取动态json数据构造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> <!-- 发送ajax请求获取动态json数据构造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节点绑定事件动态添加选项卡
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节点绑定事件动态添加选项卡 --> <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>以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
风云阁资源网 Design By www.bgabc.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
风云阁资源网 Design By www.bgabc.com
暂无评论...
更新日志
2024年11月18日
2024年11月18日
- 群星《天域原音·聆听雪域藏歌STS+SRS》[WAV+CUE]
- 尤长靖.2020-AZORAland·我是尤长靖【香蕉娱乐】【FLAC分轨】
- 群星.1995-台北爱情故事【飞碟】【WAV+CUE】
- 群星.2024-锦绣安宁电视剧原声带【D-Jin.Music】【FLAC分轨】
- 群星《闪光的夏天 第4期》[320K/MP3][97.82MB]
- 群星《闪光的夏天 第4期》[FLAC/分轨][553.31MB]
- 群星《奔赴!万人现场 第4期》[320K/MP3][80.75MB]
- 林琳《独角戏HQ》WAV
- FIM-《Super-Sound-3》声霸3[WAV+CUE]
- 喇叭花-绝版天碟《我的碟“MyDisc”》[正版原抓WAV+CUE]
- 陈慧琳.1999-真感觉【正东】【WAV+CUE】
- 徐玮.1986-走自己的路(喜玛拉雅复刻版)【同心圆】【WAV+CUE】
- 林海峰.2003-我撑你【EMI百代】【WAV+CUE】
- 群星《奔赴!万人现场 第4期》[FLAC/分轨][454.89MB]
- 腾讯音乐人《未来立体声·Stereo Future VOL.12》[320K/MP3][62.37MB]