risto
04/08/2022, 4:31 PMDaniel Mejia
04/08/2022, 4:37 PMDaniel Mejia
04/08/2022, 4:37 PMristo
04/08/2022, 4:43 PMDaniel Mejia
04/08/2022, 4:44 PMristo
04/08/2022, 4:48 PMDaniel Mejia
04/08/2022, 4:52 PMScott Steinbeck
04/08/2022, 8:02 PMfunction printTree(data, indent="", result=""){
for (child in data) { // First level
if(len(indent)) result &= indent & "└"; //only add the indent if a child
result &= child.id & "<br>"; //print id with a break
if(structKeyExists(child,"children")) //if there are children recurse with a deeper indent
result &= printTree(child["children"], indent & " ");
}
return result;
}
echo(printTree(apidata));
Scott Steinbeck
04/08/2022, 8:05 PMristo
04/08/2022, 8:12 PMDaniel Mejia
04/08/2022, 8:13 PMDaniel Mejia
04/08/2022, 8:14 PMristo
04/08/2022, 8:15 PMristo
04/08/2022, 8:16 PMDaniel Mejia
04/08/2022, 8:18 PMScott Steinbeck
04/08/2022, 8:18 PMresult &= printTree(child["children"], indent & " ");
i am adding the result of the child onto the parent’s string.
this same thing can be done with other types (array, struct, etc.)
once your finished adding everything on, you return the whole thing as one big tree and display itristo
04/08/2022, 8:22 PMbdw429s
04/09/2022, 1:09 AM