Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. [{
  2. descp: 'UNE',
  3. url: '/tree/une',
  4. icon: 'icon-list',
  5. children: [
  6. {
  7. descp: 'ATI',
  8. url: '/tree/une/ati',
  9. icon: 'icon-layers',
  10. children: [{
  11. descp: 'ATI-VC',
  12. url: '/tree/une/ati/ativc',
  13. icon: 'icon-pin',
  14. children: []
  15. },
  16. {
  17. descp: 'ATI-CMG',
  18. url: '/tree/une/ati/aticmg',
  19. icon: 'icon-pin',
  20. children: []
  21. }
  22. ]
  23. },
  24. {
  25. descp: 'EMGEF',
  26. url: '/tree/une/emgef',
  27. icon: 'icon-layers',
  28. children: []
  29. },
  30. {
  31. descp: 'ECIE',
  32. url: '/tree/une/ecie',
  33. icon: 'icon-layers',
  34. children: []
  35. },
  36. {
  37. descp: 'GEYSEL',
  38. url: '/tree/une/geysel',
  39. icon: 'icon-layers',
  40. children: []
  41. }
  42. ]
  43. }]
  44.  
  45. const MyTree = (props) => {
  46. const { list } = props;
  47. return (
  48. list.map((child,i)=>
  49. <MyTreeNestedItems key={i} data={child} />
  50. )
  51. );
  52. };
  53.  
  54.  
  55. const MyTreeNestedItems = (props) => {
  56. const { data } = props;
  57.  
  58. const createChildren = (list) => {
  59. return (
  60. list.map((child,i)=>
  61. <MyTreeNestedItems key={i} data={child} />
  62. )
  63. )
  64. }
  65.  
  66. let children = null;
  67. if (data.children.length) {
  68. children = createChildren(data.children);
  69. }
  70.  
  71. return (
  72. <li className="nav-item">
  73. <a className="nav-link" href="#">
  74. <span className={data.icon}></span> {" "}
  75. { data.descp }
  76. </a>
  77. <ul style={{listStyleType:"none"}}>{children}</ul>
  78. </li>
  79. );
  80. };
  81.  
  82. render(<MyTree list={tree} />,document.querySelector('.js-mytree'));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement