引用的js和css:
<!-- zTreeJS -->
<script type="text/javascript" src="jquery/jquery-1.7.min.js"></script><script type="text/javascript" src="zTree/js/jquery.ztree.core-3.2.js"></script><script type="text/javascript" src="zTree/js/jquery.ztree.excheck-3.2.js"></script><script type="text/javascript" src="zTree/js/jquery.ztree.exedit-3.2.js"></script>//异步加载节点var setting = { data: { key : { name : "name" }, simpleData: { enable: true, idKey: "id", pIdKey: "pId", rootPId: 0 } }, async: { //异步加载 enable: true, url: "${ctx}/admin/learn/course!publicCourseTree.do", autoParam : [ "id" ], dataType : "json", type : "post" }, check : { enable : false, chkStyle : "radio", radioType : "level" }, callback: { beforeExpand: beforeExpand, onAsyncSuccess: onAsyncSuccess, onAsyncError: onAsyncError, onClick : function(event, treeId, treeNode) { var courseID = treeNode.id; $("#courseID").val(courseID); $.post("${ctx}/admin/learn/course!getCourseTreeInfo.do?id="+courseID, { "parm":""}, function(data) { $.each(data, function(i,item) { $("#codeSM").html(item.id); $("#name").html(item.name); $("#flag").val(item.status); $("#description").html(item.description); $("#createtime").html(item.createtime); if(item.status=="1"){ $("#updateflag").val("取消发布"); $("#status").html("已发布"); }else{ $("#updateflag").val("发布"); $("#status").html("未发布"); } if(item.imgurl!=null){ $("#img").attr("src","${ctx}/uploads/"+item.imgurl); }else{ $("#img").attr("src",""); } }); }, "json"); } }};
function beforeExpand(treeId, treeNode) {
if (!treeNode.isAjaxing) { return true; } else { alert("zTree 正在下载数据中,请稍后展开节点。。。"); return false; }}function onAsyncSuccess(event, treeId, treeNode, msg) {}
function onAsyncError() { alert(" 数据加载失败");}function createTree() {
$.ajax({ url: "${ctx}/admin/learn/course!publicCourseTree.do", //url action是方法的名称 data: { id: -1 }, type: 'Get', dataType: "json", //可以是text,如果用text,返回的结果为字符串;如果需要json格式的,可是设置为json success: function (data) { $.fn.zTree.init($("#_courseTreeSM"), setting, eval(data)); }, error: function (msg) { alert(" 数据加载失败!" + msg); } }); }
$(document).ready(function () {
createTree(); });//删除var tree = $.fn.zTree.getZTreeObj("_stationTreeSM"); var node = tree.getNodeByParam("ID", response.id, null); tree.removeNode(node);
var node = treeObj.getNodeByParam("ID", response.parentid, null);//添加treeObj.addNodes(node, {ID : response.newStationID, NAME : $("#nameAS").val()});//修改node.NAME = $('#nameAS').val();treeObj.updateNode(node);
public List