Closed icruces closed 7 years ago
"To invoke a method on an instance you must obtain a reference of the instance and invoke the method". Following the current struct jsTree.directive.js, you can do following:
manageInstance: function (s, e, a) {
if (a.treeInstance) {
// Using the first way to invoke method on instance
s[a.treeInstance] = this.tree.jstree(true);
}
}
then
treeDir.manageInstance(s, e, a);
Setup attribute in view
<js-tree tree-instance="myTree" ...>
Access instance and invoke jstree method in controller
$scope.myTree.open_node('node_1');
List of available method for jstree: https://www.jstree.com/api/#/?q=(
Thank you, that's what I was looking for! Really useful to get the getSelected() method inside angular.
Thanks.
Actually since there is some activity on this thread I will add a better method:
If you add a tree-instance to the jsTree declaration:
<js-tree tree-id="dataTree" tree-instance="myTreeInstance" tree-plugins="........></js-tree>
you can access it inside the scope as follow:
$scope.myTreeInstance.deselect_all(); $scope.myTreeInstance.open_node(openFolder); $scope.myTreeInstance.select_node(selectNode);
Hi, is there any way to retrieve the jstree instance in the controller so that I can use the jsTree API?
My problem is that I have multiple trees in a page and when I select one folder I would like to deselect any selected folder in the other trees. I think it could work by calling the "deselect_all" method in each tree.
It would be good if you could bind the instance with a scope variable:
Thanks.