1.先加载整棵树,但是树是异步加载的 所以必须先递归出整课树,下面是代码。
$scope.deptTree = function() {
var treeSetting = {
async: {
enable: true,
url:"../dept/deptlist",
autoParam:["id", "name=n", "level=lv"],
otherParam:{"otherParam":"zTreeAsyncTest"}
},data: {
simpleData: {
enable: true
},
showTitle:true, //是否显示节点title信息提示 默认为true
key: {
title:"name" //设置title提示信息对应的属性名称 也就是节点相关的某个属性
}
},
callback: {
onClick:function(event, treeId, treeNode) {
$scope.tableListPtreeId = treeNode.id;
$scope.selectDeptId= treeNode.id;
$scope.usersearch="";
$scope.paginationConf.totalItems = 0;
$scope.paginationConf.currentPage = 0;
$scope.deptNode=treeNode;
$scope.treeNode=treeNode;
if($scope.tableListPtreeId!=""){
$scope.getTableList();
}
},
onAsyncSuccess :$scope.deptCtrl.onAsyncSuccess //加载完回调递归
}
};
$scope.deptCtrl = {
onAsyncSuccess:function(event, treeId, treeNode, msg) {
if(treeNode != undefined){
$scope.deptCtrl.expandNodes(treeNode.children, "tree");
}
},
expandNodes:function(nodes,treeId) {
if (!nodes) return;
var zTree=$.fn.zTree.getZTreeObj("deptTree");
for (var i=0, l=nodes.length; i
zTree.reAsyncChildNodes(nodes[i], '', true);
if (nodes[i].isParent && nodes[i].zAsync) {
expandNodes(nodes[i].children, treeId);
}
}
},
selectDept:function(){
$scope.tableListPtreeId=$scope.selectDeptId;
$scope.deptCtrl.searchNode($scope.tableListPtreeId);
// $scope.usersearch="";
// $scope.getTableList();
},
searchNode:function(nodeId){//搜索节点并且选中
console.log(nodeId);
var zTree=$.fn.zTree.getZTreeObj("deptTree");
var nodes = zTree.getNodesByParamFuzzy("id", nodeId, null);
console.log(nodes);
if (nodes.length>0) {
zTree.selectNode(nodes[0]);
}
}
};