Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jstree instance #22

Closed
icruces opened this issue Aug 5, 2015 · 4 comments
Closed

jstree instance #22

icruces opened this issue Aug 5, 2015 · 4 comments

Comments

@icruces
Copy link

icruces commented Aug 5, 2015

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:

<js-tree tree-instance="myTree" ...>

Thanks.

@oxycoder
Copy link

oxycoder commented Jan 6, 2016

"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=(

@qlux
Copy link

qlux commented Mar 22, 2016

Thank you, that's what I was looking for! Really useful to get the getSelected() method inside angular.

@icruces
Copy link
Author

icruces commented Jan 20, 2017

Thanks.

@icruces icruces closed this as completed Jan 20, 2017
@qlux
Copy link

qlux commented Jan 20, 2017

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);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants