Guest User

Untitled

a guest
Nov 18th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. https://pln kr.co/edit/dhKztoIlzoQMi7wpJwbH?p=preview
  2.  
  3. <!DOCTYPE html>
  4. <html>
  5. <head>
  6. <script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0/angular.min.js"></script>
  7. </head>
  8. <body ng-app="myApp">
  9. <div ng-controller="myCtrl as ctrl">
  10. <collection list="testdata"></collection>
  11. </div>
  12. </body>
  13. <script>
  14. angular.module('myApp',[])
  15. .controller('myCtrl', myCtrl)
  16. .directive('collection', ['$compile', collection]);
  17. function collection($compile) {
  18. return {
  19. restrict: 'E',
  20. //template: template,
  21. scope: {
  22. list: '='
  23. },
  24. transclude:true,
  25. link: linker
  26. };
  27. }
  28. var linker = function(scope, element, attrs) {
  29. var template = '<ul>';
  30. template += '<li ng-repeat="item in list">';
  31. template += '<span ng-bind="item.TagName"></span>';
  32. template += '<collection list="item.children"></collection>';
  33. template += '</li>';
  34. template += '</ul>';
  35. if (scpoe.children.length > 0) {
  36. template = 'template1'
  37. } else {
  38. template = 'template2'
  39. }
  40. element.html(template);
  41. $compile(element.contents())(scope);
  42. }
  43.  
  44. function myCtrl($scope) {
  45. $scope.testdata = [{"TagName":"MyRootNode","TagPath":">MyRootNode","children":[{"TagName":"LandXML","TagPath":">MyRootNode>ChildItems>LandXML","children":[{"TagName":"Units","TagPath":">MyRootNode>ChildItems>ChildItems[1]>Units","children":[{"TagName":"Imperial","TagPath":">MyRootNode>ChildItems>ChildItems[1]>ChildItems[1]>Imperial","children":[]},{"TagName":"Project","TagPath":">MyRootNode>ChildItems>ChildItems[1]>Project","children":[]},{"TagName":"Application","TagPath":">MyRootNode>ChildItems>ChildItems[1]>Application","children":[{"TagName":"Author","TagPath":">MyRootNode>ChildItems>ChildItems[1]>ChildItems[2]>Author","children":[]},{"TagName":"Alignments","TagPath":">MyRootNode>ChildItems>ChildItems[1]>Alignments","children":[]},{"TagName":"Roadways","TagPath":">MyRootNode>ChildItems>ChildItems[1]>Roadways","children":[{"TagName":"Roadway","TagPath":">MyRootNode>ChildItems>ChildItems[1]>ChildItems[3]>Roadway[1]","children":[]},{"TagName":"Roadway","TagPath":">MyRootNode>ChildItems>ChildItems[1]>ChildItems[3]>Roadway[2]","children":[]},{"TagName":"Roadway","TagPath":">MyRootNode>ChildItems>ChildItems[1]>ChildItems[3]>Roadway[3]","children":[]},{"TagName":"Roadway","TagPath":">MyRootNode>ChildItems>ChildItems[1]>ChildItems[3]>Roadway[4]","children":[]},{"TagName":"Roadway","TagPath":">MyRootNode>ChildItems>ChildItems[1]>ChildItems[3]>Roadway[5]","children":[]}]}]}]}]},{"TagName":"Surfaces","TagPath":">MyRootNode>ChildItems>Surfaces","children":[{"TagName":"Surface1","TagPath":">MyRootNode>ChildItems>ChildItems[2]>Surface1","children":[]},{"TagName":"Surface2","TagPath":">MyRootNode>ChildItems>ChildItems[2]>Surface2","children":[]}]}]}]
  46. }
  47. </script>
  48. </html>
Add Comment
Please, Sign In to add comment