-
Notifications
You must be signed in to change notification settings - Fork 3
/
tree-view-service.js
37 lines (28 loc) · 1 KB
/
tree-view-service.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
angular.module('ui.bootstrap.treeview', []).factory('TreeViewService', function () {
function TreeViewService() {
var that = this;
this.nodes = [];
this.selectedNode = undefined;
this.collapsed = [];
// will search all nodes for this node, and expand each parent node
this.collapseTo = function(node) {
function iterate(list) {
for (var i = 0; i < list.length; i++) {
var found = false;
if (list[i] == node) {
found = true;
} else if (angular.isDefined(list[i].children)) {
found = iterate(list[i].children);
}
if (found == true) {
that.collapsed.push(list[i]);
return true;
}
}
return false;
}
iterate(that.nodes);
};
}
return TreeViewService;
});