angularJS-Ztree

2021-06-22 06:02

阅读:412

标签:ztree

官网: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
               
                  


本文出自 “紫枫5966” 博客,请务必保留此出处http://zifeng5966.blog.51cto.com/8763113/1947635

angularJS-Ztree

标签:ztree

原文地址:http://zifeng5966.blog.51cto.com/8763113/1947635


评论


亲,登录后才可以留言!