Problem with treeview and arrays json

Problem with treeview and arrays json

This is my function

 update_tree: function()
    {
var layers = Global.Model_Layers;
  var algorithm = Global.Model_Algorithms;
  for(i = 0; i < layers.length; i++) {    
  var idlayer = layers[i].id;
  var namelayer = layers[i].name;
 
  for(j = 0; j < algorithm.length; j++)
  {
    var idalgorithm = algorithm[j].id;
    var namealgorithm = algorithm[j].name;
    var layeralgorithm = algorithm[j].layer;
  }  
  //alert (ullayer);
  }
  var data = [{label:[namelayer], children:[namealgorithm]}];
  $('#tree1').tree({data: data, autoOpen:0});
    },

The problem is that I only represents the last value in the tree and not the breakdown of this.