title: Create tree list in angular dynamically?
body: <p>I want to create a tree list in angular dynamically. I'm using the <a href="https://github.com/fer/ion-tree-list" rel="nofollow noreferrer">ion-tree-list plugin</a> to do that. I have already created some logic to create the list given the result of my request. </p>
  
  <p>So far this is what I have:</p>
  
  <pre><code>for (var i = 0; i &lt; data.records.length; i++) {
      var l1_name = null;
      var l2_name = null;
      var l3_name = null;
  
      if (data.records[i].Product_Group_Name_L1__c) {
          var has = existProduct(data.records[i]);
          if (!has) {
              l1_name = data.records[i].Product_Group_Name_L1__c;
          }
      }
  
      if (data.records[i].Product_Group_Name_L2__c) {
          var has = existProduct(data.records[i]);
          if (!has) {
              l2_name = data.records[i].Product_Group_Name_L2__c;
          }
      } else {
          // so tem um
      }
  
      if (data.records[i].Product_Group_Name_L3__c) {
          var has = existProduct(data.records[i]);
          if (!has) {
              l3_name = data.records[i].Product_Group_Name_L3__c;
          }
      } else {
  
      }
  
      if (data.records[i].Product_Group_Name_L4__c) {
          var has = existProduct(data.records[i]);
          if (!has) {
              l4_name = data.records[i].Product_Group_Name_L4__c;
          }
      } else {
          var productName = data.records[i].Name;
      }
  
      vm.tasks.push({
          name: l1_name,
          tree: [{
              name: l2_name,
              tree: [{
                  name: l3_name,
                  tree: [{
                      name: productName
                  }]
              }]
          }]
      });
  }
  
  var results = [];
  var keys = {};
  
  function existProduct(data) {
      var val = data.Product_Group_Name_L1__c;
      if (angular.isUndefined(keys[val])) {
          keys[val] = true;
          results.push(val);
          return true;
      } else {
          return false;
      }
  }
  </code></pre>
  
  <p>My <code>data.records</code> is something like this: </p>
  
  <pre><code>[{
      Product_Group_Name_L1__c: "OX",
      Product_Group_Name_L2__c: "INT",
      Product_Group_Name_L3__c: "MASC",
      Product_Group_Name_L4__c: null,
      Name: "PROD",
      ..
  }]
  </code></pre>