/* Conversion function */function (data, attributes) {Let Resdata = data;let tree = [];for] (Let i = 0; i < resdata.length; i++) {if (Resdat A[i][attributes.parentid] = = = Attributes.rootid) {Let obj = {id:resdata[i][attributes.id],title:resdata[i][ Attributes.name],children: []};tree.push (obj); Resdata.splice (I, 1); i--;}} Run (tree), function run (Chiarr) {if (resdata.length!== 0) {if (let me = 0; i < chiarr.length; i++) {for "let J = 0; J < Resdata.length; J + +) {if (chiarr[i].id = = Resdata[j][attributes.parentid]) {Let obj = {id:resdata[j][attributes.id],title:resdata[j][ Attributes.name],children: []};chiarr[i].children.push (obj); Resdata.splice (J, 1); j--;}} Run (Chiarr[i].children);}}} return tree;}
var data=[{id:1,parentid:0,name: "Test 1"},
{id:2,parentid:1,name: "Test 2"}]
Let attributes = { //Define Data property name ID: ' ID ', parentid: ' ParentID ', Name: ' GroupName ',
rootid:0}
/* Call */
Formattreedata (data,attributes);
JS transforms JSON data into tree-shaped data