官网:http://www.treejs.cn/v3/main.php#_zTreeInfo

自定义指令

/**
 * name: public.ztree
 * Version: 1.0.0 beta
 */
define(['publicZtree'], function () {
angular.module('public.ztree', []).directive('tree',[function(){
     return { 
        require: 'ngModel', 
        restrict: 'A', 
        link: function ($scope, element, attrs, ngModel) { 
          var setting = { 
            data: { 
              key: { 
                title: "branchName"
              }, 
              simpleData: { 
                enable: true
              } 
            }, 
            callback: { 
              onClick: function (event, treeId, treeNode, clickFlag) { 
                  BRANCHID = treeNode.branchId;
                  BranchID = treeNode.branchId;
                $scope.$apply(function () { 
                  ngModel.$setViewValue(treeNode); 
                }); 
              } 
            },
          }; 
          
          //向控制器发送消息,进行菜单数据的获取 
          $scope.$emit("treeCtrl",attrs["1"]);
          $scope.$on("menuData",function(event,data){ //监听或接收数据。。用于接收event与data
              $.fn.zTree.init($("#tree"), setting, data);//进行初始化树形菜单 
              //$.fn.zTree.init(element, setting, data);//进行初始化树形菜单 element
              var zTree = $.fn.zTree.getZTreeObj("tree");//zTree 的 DOM 容器的 id
              var selectName = $("#selectName").val();
              if(typeof selectName == "undefined" || selectName == ""){ 
                zTree.selectNode(zTree.getNodeByParam("tree","1"));//默认第一个选中 
                $("#selectName").val(zTree.getSelectedNodes()[0]);//赋值 
              }else{ 
                for(var i =0; i