var setting = { callback: { onClick: zTreeOnClick,//选中节点时,点击操作 simpleData:{//设置后台显示映射 enable:true, idKey:"TYPE_ID", pIdKey:"TYPE_PID", rootPId:null, } } }; //选中时执行的函数 function zTreeOnClick(event, treeId, treeNode) { $("#TYPE_ID").val(treeNode.TYPE_ID); $("#TYPE_NAME").val(treeNode.name); $("#TYPE_PID").val(treeNode.TYPE_PID); $("#TYPE_P_NAME").val(treeNode.pname); }; zTree= $.fn.zTree.init($("#tree"), setting, zNodes);//初始化生成节点数 zTree.getSelectedNodes();//获取被选中的节点对象 zTree.removeNode(nodes[0]);//删除某个节点 参数为节点对象
zTree.cancelSelectedNode();//取消选中的节点
nodes = zTree.getSelectedNodes(), treeNode = nodes[0]; if (treeNode) {//添加节点对象 有父节点 treeNode = zTree.addNodes(treeNode, { TYPE_ID: type_id, TYPE_PID: treeNode.TYPE_ID, isParent: false, name: type_name,pname:type_pname }); } else {//添加顶级节点 treeNode = zTree.addNodes(null, { TYPE_ID: type_id, TYPE_PID: 0, isParent: true, name: type_name ,pname:type_pname}); }