-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtreeDirective.js
42 lines (41 loc) · 1.47 KB
/
treeDirective.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
app.directive('jstree', function($timeout, $parse) {
return {
restrict: 'A',
require: '?ngModel',
scope: {
selectedNode: '=',
childrenUrl: '=',
selectedNodeChanged: '='
},
link: function(scope, element, attrs) {
var treeElement = $(element);
//$timeout(function() {
var tree = treeElement.jstree({
"json_data": {
"ajax": {
"url": scope.childrenUrl,
"data": function(n) {
return {
"operation": "get_children",
"id": n.attr ? n.attr("id").replace("node_", "") : 1
};
}
}
},
"plugins": ["themes", "json_data", "ui"]
});
//});
tree.bind('select_node.jstree', function() {
$timeout(function() {
scope.selectedNode = {
id: treeElement.jstree('get_selected').attr('id'),
text: treeElement.find('.jstree-clicked').text()
};
});
if (scope.selectedNodeChanged) $timeout(function() {
scope.selectedNodeChanged(scope.selectedNode);
});
});
}
};
});