Guest User

Untitled

a guest
Jun 21st, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.65 KB | None | 0 0
  1. import {ITreeComponent} from './tree.component';
  2.  
  3. export const trees:ITreeComponent[] = [
  4. {
  5. "leaf":true,
  6. "parentCategoryId":10001,
  7. "categoryName":"Первый родитель",
  8. "categoryId":10500,
  9. "url":"first-parent",
  10. "trees":
  11. [{
  12. "leaf":false,
  13. "parentCategoryId":10500,
  14. "categoryName":"Ребенок первого родителя",
  15. "categoryId":10515,
  16. "url":"children-first-parent",
  17. "trees":[]
  18. }]
  19. },
  20. {
  21. "leaf":true,
  22. "parentCategoryId":10001,
  23. "categoryName":"Второй родитель",
  24. "categoryId":10102,
  25. "url":"second-parent",
  26. "trees":
  27. [{
  28. "leaf":true,
  29. "parentCategoryId":10102,
  30. "categoryName":"Первый ребенок второго родителя",
  31. "categoryId":10614,
  32. "url":"first-children-second-parent",
  33. "trees":
  34. [{
  35. "leaf":false,
  36. "parentCategoryId":10614,
  37. "categoryName":"Внук",
  38. "categoryId":10633,
  39. "url":"vanok",
  40. "trees":[]
  41. },
  42. {
  43. "leaf":false,
  44. "parentCategoryId":10614,
  45. "categoryName":"Внучара",
  46. "categoryId":10634,
  47. "url":"big-boy",
  48. "trees":[]
  49. },
  50. {
  51. "leaf":false,
  52. "parentCategoryId":10614,
  53. "categoryName":"Внучка",
  54. "categoryId":10867,
  55. "url":"top-one-princes-good-girl",
  56. "trees":[]
  57. }]
  58. },
  59. {
  60. "leaf":true,
  61. "parentCategoryId":10102,
  62. "categoryName":"Второй ребенок второго родителя",
  63. "categoryId":10473,
  64. "url":"second-children-second-parent",
  65. "trees":
  66. [{
  67. "leaf":false,
  68. "parentCategoryId":10473,
  69. "categoryName":"Внук",
  70. "categoryId":10478,
  71. "url":"vano",
  72. "trees":[]
  73. },
  74. {
  75. "leaf":false,
  76. "parentCategoryId":10473,
  77. "categoryName":"Внучка",
  78. "categoryId":10475,
  79. "url":"olya",
  80. "trees":[]
  81. }]
  82. }]
  83. },
  84. {
  85. "leaf":true,
  86. "parentCategoryId":10001,
  87. "categoryName":"Соседка из квартиры 66",
  88. "categoryId":10105,
  89. "url":"sosedka-rembo",
  90. "trees":
  91. [{
  92. "leaf":false,
  93. "parentCategoryId":10105,
  94. "categoryName":"Сын маминой подруги",
  95. "categoryId":10360,
  96. "url":"cool-boy",
  97. "trees":[]
  98. }]
  99. }
  100. ];
  101.  
  102. import { Component, Input, Output, EventEmitter } from '@angular/core';
  103.  
  104. export interface ITreeComponent {
  105. leaf: boolean;
  106. parentCategoryId: number;
  107. categoryName: string;
  108. categoryId: number;
  109. url: string;
  110. trees?: Array<ITreeComponent>;
  111. }
  112.  
  113. @Component({
  114. selector: 'trees',
  115. template: `
  116. <ul class="TreeComponents">
  117. <div *ngFor="let tree of trees" class="TreeComponent">
  118. <i *ngIf="tree.leaf" class="NodeButton fa fa-caret-square-o-down"></i>
  119. <ul>
  120. <li>
  121. (Parent: {{tree.parentCategoryId}})
  122. {{tree.categoryName}}.
  123. Id: {{tree.categoryId}}.
  124. <trees [trees]="tree.trees" *ngIf="tree.trees">
  125. </trees>
  126. </li>
  127. </ul>
  128. </div>
  129. </ul>
  130. `,
  131. styleUrls: ["./tree.component.css"]
  132. })
  133.  
  134. export class TreeComponent {
  135. isExpanded: boolean;
  136. @Input() trees: Array<ITreeComponent>;
  137. @Input() SelectedNode: ITreeComponent;
  138.  
  139. @Output() onSelectedChanged: EventEmitter<ITreeComponent> = new EventEmitter<ITreeComponent>();
  140. @Output() onRequestNodes: EventEmitter<ITreeComponent> = new EventEmitter<ITreeComponent>();
  141.  
  142. constructor(){}
  143.  
  144. onSelectNode(node: ITreeComponent) {
  145. this.onSelectedChanged.emit(node);
  146. }
  147.  
  148. onRequestLocal(node: ITreeComponent) {
  149. this.onRequestNodes.emit(node);
  150. }
  151. }
  152.  
  153. import { Component } from '@angular/core';
  154. import { trees } from './tree/tree-data';
  155.  
  156. @Component({
  157. selector: 'my-app',
  158. templateUrl: './app.component.html',
  159. styleUrls: ['./app.component.css']
  160. })
  161. export class AppComponent {
  162. name = 'Angular 6';
  163. treesData = trees;
  164. }
  165.  
  166. <div>
  167. <h1>Пробный рекурсивный вывод</h1>
  168. <trees [trees]="treesData"></trees>
  169. </div>
Add Comment
Please, Sign In to add comment