<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Ztree</title> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="this is my page"> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/css/zTreeStyle.css"> <script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-1.9.1.min.js"></script> <script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery.ztree.core.js"></script> <script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery.ztree.excheck.min.js"></script> <script type="text/javascript"> /** *非同步載入的意思就是: 當點擊展開樹節點時, *才去請求後台action返回點擊節點的子節點 *資料並載入。 */ var setting = { data : { key:{ name:"catalogName" }, simpleData : { enable : true, idKey:"catalogId", pIdKey:"parentId", } }, async : { enable : true, url : "ztree/list.ht", autoParam : [ "catalogId", "catalogName" ], dataFilter : filter //非同步返回後經過Filter }, callback : { // beforeAsync: zTreeBeforeAsync, // 非同步載入事件之前得到相應資訊 OnAsyncSuccess : zTreeOnAsyncSuccess,//非同步載入成功的fun aOnAsyncError : zTreeOnAsyncError, //載入錯誤的fun beforeClick : beforeClick,//捕獲單擊節點之前的事件回呼函數 onRightClick: zTreeOnRightClick } }; //treeId是treeDemo,非同步載入完之後走這個方法 function filter(treeId, parentNode, childNodes) { if (!childNodes) return null; childNodes = eval(childNodes); return childNodes; } //點擊節點觸發事件 function beforeClick(treeId, treeNode) { if (!treeNode.isParent) { alert("請選擇父節點"); return false; } else { return true; } } //非同步載入失敗走該方法 function zTreeOnAsyncError(event, treeId, treeNode) { alert("非同步載入失敗!"); } //非同步載入成功走該方法 function zTreeOnAsyncSuccess(event, treeId, treeNode, msg) { } //右擊事件 function zTreeOnRightClick(){ alert("asdas"); } /**********當你點擊父節點是,會非同步訪問controller,把id傳過去*************/ var zNodes = []; $(document).ready(function() { $.fn.zTree.init($("#treeDemo"), setting, zNodes); }); </script> </head> <body> <div style="height:600px; width:98%"> <div style="height:600px; width:20%; border:1px solid #999999; float:left"> <ul id="treeDemo" class="ztree"></ul> </div> <div style="height:600px; width:79.5%; border:1px solid #999999; float:left; overflow:auto"> <iframe id="testIframe" name="testIframe" frameborder=0 scrolling=auto width=90% height=580px src="ztree/welcome.ht"></iframe> </div> </div> </body> </html> |