<script type="text/javascript"
src="../../resources/zTree_v3/js/jquery.ztree.core-3.5.min.js"></script>
<script type="text/javascript">
//定义树数据
var datas = [ {
id : "0",
name : "根栏目",
pid : "-1",
createDate:"1990-08-09"
}, {
id : "1",
name : "栏目管理",
pid : "0",
createDate:"1990-08-09"
}, {
id : "2",
name : "文章管理1",
pid : "1",
createDate:"1990-08-09"
} ];
//回调函数
function zTreeOnClick(event, treeId, treeNode) {
alert(treeNode.name + ", " + treeNode.createDate+","+treeNode.isParent);
};
$(document).ready(function() {
//2.在setting中设置配置信息
var setting = {
data : {
simpleData : {
enable : true,
idKey : "id",
pIdKey : "pid",
rootPId : -1,
}
},
view : {
dblClickExpand : false,
selectedMulti : false,
},
//回调函数
callback: {
onClick: zTreeOnClick
}
};
//显示树,返回的是一个树的对象
var tree=$.fn.zTree.init($("#treeDemo"), setting, datas);
//获得父级节点
var node = tree.getNodeByParam("id", 1, null);
var newNode = {id:"3",name:"newNode1",pid:"1",createDate:"2013-05-06"};
//将新节点添加到父级节点
newNode = tree.addNodes(node, newNode);
});
</script>