Guest User

Untitled

a guest
Jan 17th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. var miArray= [
  2. { nivel:"Cluster", cantidad:4 },
  3. { nivel:"Sección", cantidad:3 },
  4. { nivel:"Manzanas", cantidad:2 },
  5. ];
  6.  
  7. Manzanas 1
  8.  
  9. Manzanas 2
  10.  
  11. Manzanas 1
  12.  
  13. Manzanas 2
  14.  
  15. Manzanas 1
  16.  
  17. Manzanas 2
  18.  
  19. Manzanas 1
  20.  
  21. Manzanas 2
  22.  
  23. Manzanas 1
  24.  
  25. Manzanas 2
  26.  
  27. Manzanas 1
  28.  
  29. Manzanas 2
  30.  
  31. $('#using_json_2').jstree({ 'core' : {
  32. 'data' : [
  33. { "id" : "ajson1", "parent" : "#", "text" : "Simple root node" },
  34. { "id" : "ajson2", "parent" : "#", "text" : "Root node 2" },
  35. { "id" : "ajson3", "parent" : "ajson2", "text" : "Child 1" },
  36. { "id" : "ajson4", "parent" : "ajson2", "text" : "Child 2" },
  37. ]
  38. } });
  39.  
  40. var miArray= [
  41. { nivel:"Cluster", cantidad:4 },
  42. { nivel:"Sección", cantidad:3 },
  43. { nivel:"Manzanas", cantidad:2 },
  44. ];
  45. var data = [];
  46.  
  47. recorreNiveles(miArray);
  48. console.log(data);
  49.  
  50. function recorreNiveles(niveles){
  51.  
  52. var copy = niveles;
  53.  
  54. if (niveles !== undefined && niveles.length){
  55. for (var f =0; f < niveles.length; f++){
  56. var item = niveles[f];
  57. console.log("nivel:"+item.nivel+"_"+f)
  58. for (var g =0; g < item.cantidad; g++) {
  59. console.log("nivel:"+item.nivel+"_"+g)
  60.  
  61.  
  62. console.log('length:'+copy.length);
  63. recorreNiveles(copy.shift());
  64. /*
  65. for (var h=g+1; h < niveles.length; h++ ){
  66. var nivel = niveles[h];
  67. console.log(nivel);
  68. for (var i = 0; i < nivel.cantidad; i++){
  69. console.log(" nivel:"+nivel.nivel+"_"+i)
  70. }
  71. }
  72. */
  73. }
  74. }
  75.  
  76. }
  77. }
Add Comment
Please, Sign In to add comment