Angularjs 如何折叠每个角度UI树上的所有函数

Angularjs 如何折叠每个角度UI树上的所有函数,angularjs,collapse,expand,Angularjs,Collapse,Expand,对于Angular ui树,我希望添加expland all或折叠all 我尝试了下面的代码,它是有效的 $scope.collapseAll = function () { $scope.$broadcast('angular-ui-tree:collapse-all'); }; $scope.expandAll = function () { $scope.$broadcast('angular-ui-tree:expand-all'); };

对于Angular ui树,我希望添加expland all或折叠all

我尝试了下面的代码,它是有效的

 $scope.collapseAll = function () {
        $scope.$broadcast('angular-ui-tree:collapse-all');
      };

  $scope.expandAll = function () {
    $scope.$broadcast('angular-ui-tree:expand-all');
  };
  ...
问题是,我的页面有多个ui树,我只想单独触发expandAll函数。现在我触发这个expandAll函数所有用户界面-树将受到影响

有没有办法将每一个单独设置

如果在angular ui树的顶部进行检查,则
'angular-ui-tree:collapse all'
事件将切换范围值。另一个问题是angular ui树中的每个指令都继承父级的作用域,而不是具有独立的作用域。因此,在广播事件时更改范围实际上是在更改相同的范围值


您应该找到一种方法,让每棵树都有一个单独的作用域,或者考虑使用其他类似的树

我们应该广播指定树范围的ui树:全部折叠。 这是我的工作。你可以毫不犹豫地使用它

    function collapseAll() {
        var treeScope = _getRootNodesScope('myTreeId');
        if (treeScope) {
            treeScope.$broadcast('angular-ui-tree:collapse-all');
        }
    }


 function expandAll() {
        var treeScope = _getRootNodesScope('userTreeroot');
        if (treeScope) {
            treeScope.$broadcast('angular-ui-tree:expand-all');
        }
    }

  function _getRootNodesScope(myTreeId) {
 var treeElement = angular.element(document.getElementById(myTreeId));
 if (treeElement) {
 var treeScope = (typeof treeElement.scope === 'function') ? 
 treeElement.scope() : undefined;
            return treeScope;
        }
        return undefined;
    };

谢谢你的回复。V手风琴是一款神奇的插件,以后会考虑使用它。无论如何,我使用while循环递归地获取childNode,可以解决这个问题。谢谢