如何以编程方式折叠所有 ng-js-tree 节点
How collapse all ng-js-tree nodes programmatically
我使用 ng-js-tree https://github.com/ezraroi/ngJsTree
我从 json 加载树并尝试使用两种方式折叠所有节点(state.opened 和 close_all):
$http.get('resources/json/mkb10.json')
.then(function(res){
$scope.cond.treeData = res.data;
if (data !== undefined){
for (var i = 0; i < $scope.cond.treeData.length; i++){
$scope.cond.treeData[i].state = {};
for (var j = 0; j < data.cond.length; j++)
if ($scope.cond.treeData[i].id == data.cond[j]){
$scope.cond.treeData[i].state = {selected: true};
}
$scope.cond.treeData[i].state.opened = false;
}
}
$scope.treeInstance.jstree(true).close_all();
$scope.treeConfig.version++;
$scope.treeInstance.jstree(true).close_all();
});
我的结果是:
但两者都没有必要的结果。
谁知道,如何折叠所有节点?谢谢!
例如我写了plunker
我想获得这个视图:
在使用树api之前,您应该等待树的就绪事件。
查看 GitHub 上的演示代码:
https://github.com/ezraroi/ngJsTree
此外,当您增加版本时,您正在重新创建树,我认为这不是您想要做的。
如果这对您没有帮助,请写一个 plunker 并分享它,以便我能够帮助您
我将 jstree.js 替换为 3.0.8 并赢得了这个)
<script src="https://rawgit.com/ezraroi/ngJsTree/master/demo/bower_components/jstree/dist/jstree.js"></script>
<!--script src="https://rawgit.com/vakata/jstree/master/dist/jstree.js"></script-->
我使用 ng-js-tree https://github.com/ezraroi/ngJsTree 我从 json 加载树并尝试使用两种方式折叠所有节点(state.opened 和 close_all):
$http.get('resources/json/mkb10.json')
.then(function(res){
$scope.cond.treeData = res.data;
if (data !== undefined){
for (var i = 0; i < $scope.cond.treeData.length; i++){
$scope.cond.treeData[i].state = {};
for (var j = 0; j < data.cond.length; j++)
if ($scope.cond.treeData[i].id == data.cond[j]){
$scope.cond.treeData[i].state = {selected: true};
}
$scope.cond.treeData[i].state.opened = false;
}
}
$scope.treeInstance.jstree(true).close_all();
$scope.treeConfig.version++;
$scope.treeInstance.jstree(true).close_all();
});
我的结果是:
但两者都没有必要的结果。 谁知道,如何折叠所有节点?谢谢!
例如我写了plunker
我想获得这个视图:
在使用树api之前,您应该等待树的就绪事件。 查看 GitHub 上的演示代码: https://github.com/ezraroi/ngJsTree
此外,当您增加版本时,您正在重新创建树,我认为这不是您想要做的。
如果这对您没有帮助,请写一个 plunker 并分享它,以便我能够帮助您
我将 jstree.js 替换为 3.0.8 并赢得了这个)
<script src="https://rawgit.com/ezraroi/ngJsTree/master/demo/bower_components/jstree/dist/jstree.js"></script>
<!--script src="https://rawgit.com/vakata/jstree/master/dist/jstree.js"></script-->