Advertisement
regergr

Untitled

Dec 27th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Int</title>
  6. </head>
  7. <body>
  8. <script>
  9. var data = [
  10. {
  11. text: 'Животные',
  12. children: [
  13. {
  14. text: 'Млекопитающий',
  15. children: [
  16. {
  17. text: 'Коровы',
  18. children: []
  19. },
  20. {
  21. text: 'Ослы',
  22. children: []
  23. },
  24. {
  25. text: 'Собаки',
  26. children: []
  27. },
  28. {
  29. text: 'Тигры',
  30. children: []
  31. }
  32. ]
  33. },
  34. {
  35. text: 'Другие',
  36. children: [
  37. {
  38. text: 'Змеи',
  39. children: []
  40. },
  41. {
  42. text: 'Птицы',
  43. children: []
  44. },
  45. {
  46. text: 'Ящерицы',
  47. children: []
  48. }
  49. ]
  50. }
  51. ]
  52. },
  53. {
  54. text: 'Рыбы',
  55. children: [
  56. {
  57. text: 'Аквариумные',
  58. children: [
  59. {
  60. text: 'Гуппи',
  61. children: []
  62. },
  63. {
  64. text: 'Скалярии',
  65. children: []
  66. }
  67. ]
  68. },
  69. {
  70. text: 'Морские',
  71. children: [
  72. {
  73. text: 'Морская форель',
  74. children: []
  75. }
  76. ]
  77. }
  78. ]
  79. }];
  80. /* 5.1 */
  81. function recCreate(obj)
  82. {
  83. var element = document.createElement("li");
  84. element.innerText = obj.text
  85. if (obj.children.length != 0)
  86. {
  87. var elementUL = document.createElement("ul");
  88. for (var i = 0; i < obj.children.length; i++)
  89. elementUL.append(recCreate(obj.children[i]))
  90.  
  91. element.append(elementUL)
  92. }
  93. return element;
  94. }
  95. var element = document.createElement("ul");
  96. for (var i = 0; i < data.length; i++)
  97. element.append(recCreate(data[i]))
  98. document.body.insertBefore(element, document.getElementsByTagName("script")[0]);
  99. /* ~5.1 */
  100. /* 5.2 */
  101. function recGetInfo(obj)
  102. {
  103. var infoNode = {node: obj, props: []}
  104. for(var key in obj)
  105. infoNode.props.push(key + ": " + obj[key])
  106. console.log(infoNode)
  107. for (var i = 0; i < obj.children.length; i++)
  108. recGetInfo(obj.children[i])
  109. }
  110. recGetInfo(document.documentElement)
  111. /* ~5.2 */
  112. </script>
  113. </body>
  114. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement