首页 > 代码库 > zTree的使用
zTree的使用
zTree的使用
js函数:
<link rel="stylesheet" href="css/zTreeStyle/zTreeStyle.css" type="text/css"></link> <script type="text/javascript" src="js/zTree/jquery.ztree.core-3.5.js"></script> <script type="text/javascript"> $(document).ready(function(){ $.fn.zTree.init($("#treeDemo"), setting); }); var setting = { data: { key: { name: "cName" } }, async: { enable: true, url:"search_child" }, callback: { beforeAsync: beforeAsync, onAsyncError: onAsyncError, onAsyncSuccess: onAsyncSuccess, onClick: onClick } }; function onClick(event, treeId, treeNode, clickFlag) { $.ajax( { url:"to_edit_category.action?id="+treeNode.id, dataType:"html", success:function(data) { document.getElementById("displayId").innerHTML=data; } }) } var log, className = "dark"; function beforeAsync(treeId, treeNode) { className = (className === "dark" ? "":"dark"); //showLog("[ "+getTime()+" beforeAsync ] " + ((!!treeNode && !!treeNode.name) ? treeNode.name : "root") ); return true; } function onAsyncError(event, treeId, treeNode, XMLHttpRequest, textStatus, errorThrown) { //showLog("[ "+getTime()+" onAsyncError ] " + ((!!treeNode && !!treeNode.name) ? treeNode.name : "root") ); } function onAsyncSuccess(event, treeId, treeNode, msg) { //showLog("[ "+getTime()+" onAsyncSuccess ] " + ((!!treeNode && !!treeNode.name) ? treeNode.name : "root") ); } function showLog(str) { if (!log) log = $("#log"); log.append("<li class=‘"+className+"‘>"+str+"</li>"); if(log.children("li").length > 8) { log.get(0).removeChild(log.children("li")[0]); } } function getTime() { var now= new Date(), h=now.getHours(), m=now.getMinutes(), s=now.getSeconds(), ms=now.getMilliseconds(); return (h+":"+m+":"+s+ " " +ms); } </script>
页面元素:
<div> <ul id="treeDemo" class="ztree"></ul> <ul id="log" class="log"></ul> </div> <br /> <div id="displayId"> Please click on any of the tree nodes. </div>
分析:通过setting加载树节点数据,通过onClick函数,为节点加载函数。
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。