1

I load my tree successfully using a directive in AngularJS.Now i want to add events (here select node) in my tree, so i did like this. but i can't see my alert .

My code:

app.directive('jstree', function() {
  return {
    restrict: 'A',
     scope: {
          jstree: '='
         }, 

link: function(scope, element, attrs) 
      {        
       scope.$watch('jstree', function() 
         {

           $(element).jstree({

                          "json_data" :{
                            "data":scope.jstree.data
                            },

                           "themes" : {
                                     "theme" : "classic",
                                      "dots" : true,
                                     "icons" : true
                                    },
                            "plugins" : [ "themes", "json_data" ]
                        }, false); 
            }, true);

            // select a node
            element.bind("select_node.jstree",function(e, data) {
     $window.alert(e.data);

                        });

             }
          };
});

Any idea were i went wrong ?

2
  • Can you try to store the reference of $(element).jstree({...}) in a variable such as tree and then do tree.bind Commented Jul 10, 2013 at 13:07
  • @Chandermani, i try it, but i still have no result. Commented Jul 10, 2013 at 13:22

2 Answers 2

1

To use events in jstree, you have to add "ui" in this line :

"plugins" : [ "themes", "json_data", "ui" ]

Now it works.

Sign up to request clarification or add additional context in comments.

Comments

0

Looking at the jstree demo, you'll want to call bind on the jstree object, not on the element (you'll be able to bind to click on the element, but this probably isn't what you want)

$(element)
  .jstree({
    "json_data" : {
        "data" : scope.jstree.data
    },
    "themes" : {
        "theme" : "classic",
        "dots" : true,
        "icons" : true
    },
    "plugins" : ["themes", "json_data"]
  }, false)
  .bind('select_node.jstree', function(ev,data) {
    console.log('clicked');
  });

1 Comment

hi @leon, i did that, and no result, in my console, i can't see the word clicked . thks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.