博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【笔记】ztree的使用
阅读量:6533 次
发布时间:2019-06-24

本文共 5700 字,大约阅读时间需要 19 分钟。

引用的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
> getPublicCourseTree(String id, Integer orgID) { List
> list1 = new ArrayList
>(); List
> list2 = new ArrayList
>(); if (null == id && !"".equals(id)){ String hql="SELECT t.id, t.name, t.parentid as pid,t.description,DATE_FORMAT(t.createtime, '%Y-%m-%d') createtime,t.status,t.imgurl,(SELECT COUNT(t2.id) FROM c_publiccourse_tab t2 WHERE t2.parentid = t.id) coun FROM c_publiccourse_tab t WHERE t.PARENTID = -1 and t.orgid='"+orgID+"'"; Query query = super.createSQLQuery(hql).addScalar( "id" , Hibernate.STRING).addScalar( "name" , Hibernate.STRING).addScalar( "pid" , Hibernate.STRING) .addScalar( "description" , Hibernate.STRING).addScalar( "createtime" , Hibernate.STRING).addScalar( "status" , Hibernate.STRING).addScalar( "imgurl" , Hibernate.STRING).addScalar( "coun" , Hibernate.STRING).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP); list1=query.list(); }else{ String hql = "SELECT t.id, t.name , t.parentid as pid,t.description,DATE_FORMAT(t.createtime, '%Y-%m-%d') createtime,t.status,t.imgurl,(SELECT COUNT(t2.id) FROM c_publiccourse_tab t2 WHERE t2.parentid = t.id) coun FROM c_publiccourse_tab t WHERE t.PARENTID ='" + id +"' and t.orgid='"+orgID+"' order by t.id asc"; Query query = super.createSQLQuery(hql).addScalar( "id" , Hibernate.STRING).addScalar( "name" , Hibernate.STRING).addScalar( "pid" , Hibernate.STRING) .addScalar( "description" , Hibernate.STRING).addScalar( "createtime" , Hibernate.STRING).addScalar( "status" , Hibernate.STRING).addScalar( "imgurl" , Hibernate.STRING).addScalar( "coun" , Hibernate.STRING).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP); list1=query.list(); } for (Map
map : list1){ map.put("open", true); String parentid = map.get("pid").toString(); if (parentid.equals("-1")){ map.put("open", true); int count = Integer.parseInt(map.get("coun").toString()); if (count > 0){ map.put("isParent", true); }else{ map.put("isParent", false); } }else{ int count = Integer.parseInt(map.get("coun").toString()); if (count > 0){ map.put("isParent", true); } } list2.add(map); } return list2; } List
> data=publicCourseManager.getPublicCourseTree2(id,orgID); try { response.getWriter().write(JSONArray.fromObject(data).toString()); } catch (IOException e) { e.printStackTrace(); }

 

转载于:https://www.cnblogs.com/mybug/p/6251681.html

你可能感兴趣的文章
[转]分享2011年8个最新的jQuery Mobile在线教程
查看>>
android call require api level
查看>>
Mac下android环境搭建
查看>>
创建Visual Studio项目模版向导的几篇参考文章
查看>>
深入浅出SQL Server Replication第一篇:走近Replication(上)
查看>>
[TopCoder][SRM] SRM 562 DIV 2
查看>>
SQLSERVER是怎麽通过索引和统计信息来找到目标数据的(第一篇)
查看>>
LocalAlloc,VirtualAlloc,malloc,new的异同
查看>>
回调函数
查看>>
win7 x64 jdk1.7.0_51
查看>>
这些开源项目,你都知道吗?(持续更新中...)[原创]
查看>>
linux中利用iptables+geoip过滤指定IP
查看>>
在myeclipse中写sql语句的细节问题
查看>>
使用ShellExecute打开目标文件所在文件夹并选中目标文件
查看>>
HDU 4614 Vases and Flowers (2013多校2 1004 线段树)
查看>>
Minix中的字符判定ctype.c
查看>>
91平台iOS接入demo
查看>>
五个优秀的硬盘检测工具
查看>>
用js实现table内容从下到上连续滚动
查看>>
基于ffmpeg的流媒体服务器
查看>>