首页 > 代码库 > angular ztree

angular ztree

// 获取树数据
        $scope.initZtreeData =http://www.mamicode.com/ 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: ‘‘
                        }
                    },
                    callback: {
                        onClick: zTreeOnCheck //点击节点时 回调
                    }
                };
                var zTree = $.fn.zTree.init($("#functionLimitList"),setting,$scope.zNodes);//初始化
                var functionLimitList = $.fn.zTree.getZTreeObj("functionLimitList");
                functionLimitList.expandAll(true);//默认展开所有
            }).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;

};
 

 

angular ztree