Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. $scope.tree = Tree.parentize({
  2. title: 'root',
  3. children: [{
  4. title: 'child one',
  5. children: [{
  6. title: 'leaf one',
  7. children: []
  8. }, {
  9. title: 'leaf two',
  10. children: []
  11. }, {
  12. title: 'leaf three',
  13. children: []
  14. }]
  15. }, {
  16. title: 'child two',
  17. children: [{
  18. title: 'leaf four',
  19. children: []
  20. }, {
  21. title: 'leaf five',
  22. children: []
  23. }]
  24. }]
  25. });
  26.  
  27. 'use strict';
  28.  
  29. var Tree = (function () {
  30. var parentize = function(tree) {
  31.  
  32. angular.forEach(tree.children, function(value, key) {
  33. this.children[key].parent = function() {
  34. return tree;
  35. };
  36. parentize(value);
  37. }, tree);
  38. return tree;
  39. };
  40.  
  41. return {
  42. parentize: parentize
  43. };
  44. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement