javascript - Create tree list in angular dynamically? -


i want create tree list in angular dynamically. i'm using ion-tree-list plugin that. have created logic create list given result of request.

so far have:

for (var = 0; < 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 {         // 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;     } } 

my data.records this:

[{     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",     .. }] 

the online example (http://fer.github.io/ion-tree-list/) shows how create dynamic data via generatesamplenodes(obj, num), showing possible modify tree on demand.

https://github.com/fer/ion-tree-list/blob/gh-pages/app.js


Comments