How to use jsTree events with AngularJS

断了今生、忘了曾经 提交于 2019-12-08 10:47:08

问题


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 ?


回答1:


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

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

Now it works.




回答2:


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


来源:https://stackoverflow.com/questions/17570895/how-to-use-jstree-events-with-angularjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!