// 獲取樹數據 $scope.initZtreeData = function () { var url = '/bpopstation/func/queryAll.do'; $http.post(url).success(function(res){ $scope.zNodes = res.respData;//賦值 var setting = { view: { dblClickExpand: false, showLine: true, selectedMulti: false }, data: { key: { name: "funcName",//設置樹顯示的字段與接口里的字段對應關系 tId: "id", children: "subFuncsList",//子節點名稱與接口字段對應關系,梯形數據結構需要 }, simpleData: { enable:false,//禁用簡單的json數據結構,即用梯形結構 idKey: "funcCode",//設置id與接口字段對應關系(可以根據id找到當前節點) pIdKey: "parentCode",//設置子pid與接口字段對應關系(可以根據pid找到父節點) rootPId: '' } },
check:{
enable:true,//開啟樹的checkbox,也可以設置為radio
}, callback: { onClick: zTreeOnCheck //點擊節點時 回調 } }; var zTree = $.fn.zTree.init($("#functionLimitList"),setting,$scope.zNodes);//初始化 var functionLimitList = $.fn.zTree.getZTreeObj("functionLimitList"); functionLimitList.expandAll(true);//默認展開所有
functionLimitList.setting.check.chkboxType = { "Y" : "ps", "N" : "ps" };//checkbox 選中/取消選中的時候關聯到父子節點 p-父 s-子
}).error(function(){});
};
$scope.initZtreeData();
function zTreeOnCheck(){
$scope.getNodeDetail();
};
//點擊節點時執行的回調
$scope.getNodeDetail = function () {
var treeObj = $.fn.zTree.getZTreeObj("functionLimitList");
var node = treeObj.getSelectedNodes();//點擊節點后 獲取節點數據
$scope.id = node[0].id;
};
默認選中節點:(備注:默認選中的方法應該在樹成功以后調用 才能保證每次check成功)
$scope.roleZtreeDafultNodes = function () { var url = '/';//接口名 var params = { // 參數 }; $http.post(url,params).success(function(res){ var list = [110101,110102];//res.data里 獲取到的節點id for(var i=0;i<list.length;i++){ var node = zTree.getNodeByParam("id",list[i]); zTree.checkNode(node); zTree.expandNode(node, true, true,true); zTree.selectNode(node); }; }).error(function(){}); }; $scope.roleZtreeDafultNodes();
