added json tree directive, refactoring model tree
parent
af3fe93b3e
commit
64abdd2f76
@ -0,0 +1,47 @@
|
||||
// JSON tree
|
||||
panelApp.directive('batJsonTree', function($compile) {
|
||||
return {
|
||||
restrict: 'E',
|
||||
terminal: true,
|
||||
scope: {
|
||||
val: '=',
|
||||
//edit: '=',
|
||||
},
|
||||
link: function (scope, element, attrs) {
|
||||
// this is more complicated then it should be
|
||||
// see: https://github.com/angular/angular.js/issues/898
|
||||
|
||||
//var childScope = scope.$new();
|
||||
|
||||
|
||||
var buildDom = function (object) {
|
||||
var html = '';
|
||||
if (object == undefined) {
|
||||
html += 'null';
|
||||
} else if (object instanceof Array) {
|
||||
var i;
|
||||
html += '<div class="scope-branch">['
|
||||
for (i = 0; i < object.length; i++) {
|
||||
html += buildDom(object[i]) + ', ';
|
||||
}
|
||||
html += ']</div>'
|
||||
} else if (object instanceof Object) {
|
||||
for (prop in object) {
|
||||
if (object.hasOwnProperty(prop)) {
|
||||
html += '<div class="scope-branch">' + prop + ': ' + buildDom(object[prop]) + '</div>';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
html += '<span>' + object.toString() + '</span>';
|
||||
}
|
||||
return html;
|
||||
};
|
||||
|
||||
scope.$watch('val', function (newVal, oldVal) {
|
||||
// TODO: clean up scopes
|
||||
element.html(buildDom(newVal));
|
||||
//$compile(element.contents())(scope);
|
||||
});
|
||||
}
|
||||
};
|
||||
});
|
Reference in New Issue