function jsTreeCtrl() {
/*jshint validthis:true */
var nodeSerialId = 1;
+ var vm = this;
- this.nodesFingerprint = function (e) {
+ vm.nodesFingerprint = function (e) {
if (!e.__uiNodeId) {
e.__uiNodeId = nodeSerialId++;
}
return '' + e.__uiNodeId + (e.id || '') + (e.text || '') + (e.type || '');
};
- this.changeWatcher = function (arraySource, tokenFn) {
+ vm.changeWatcher = function (arraySource, tokenFn) {
var self;
var getTokens = function () {
var result = [], token, el;
restrict: 'A',
scope: {
treeData: '=ngModel',
+ treeEventsObj: '=?treeEventsObj',
shouldApply : '&'
},
controller: 'jsTreeCtrl',
s.tree.on(evt, s.$parent.$eval(cb));
}
}
+ } else if (angular.isObject(s.treeEventsObj)) {
+ angular.forEach(s.treeEventsObj, function(cb, name) {
+ var evt = name + '.jstree';
+ s.tree.on(evt, cb);
+ });
}
}
if (attrs.tree) {
if (attrs.tree.indexOf('.') !== -1) {
var split = attrs.tree.split('.');
- scope.tree = scope.$parent[split[0]][split[1]] = elm;
+ var tree = split.pop();
+ var context = scope.$parent;
+ for (var i = 0; i < split.length; i++) {
+ context = context[split[i]];
+ }
+ scope.tree = context[tree] = elm;
}
else {
scope.tree = scope.$parent[attrs.tree] = elm;