问题
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