我使用AngularJS
中的指令成功加載我的樹。現在我想在我的樹中添加事件(這裏選擇節點),所以我喜歡這樣。但我看不到我的警報。如何在AngularJS中使用jsTree事件
我的代碼:
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);
});
}
};
});
任何想法是我在哪裏呢?
您可以嘗試在'tree'等變量中存儲'$(element).jstree({...})'的引用,然後執行'tree.bind' – Chandermani
@Chandermani,我試試看,但我仍然沒有結果。 –