I encountered a similar issue like the one discussed in this post (Get a tree like structure out of path string). I attempted to implement the suggested solution but I am facing difficulties getting it to work within an Angular context.
The concept involves parsing incoming path strings (as shown below) and organizing them into an object to be displayed as a tree.
pathStrings: string[] = [
"PathA/PathA_0",
"PathA/PathA_1",
"PathA/PathA_2/a",
"PathA/PathA_2/b",
"PathA/PathA_2/c"
];
let tree: Node[] = [];
for (let i = 0; i < this.pathStrings.length; i++) {
tree = this.addToTree(tree, this.pathStrings[i].split("/"));
}
// function addToTree...
const TREE_DATA: Node[] = [
// Tree data example...
];
</div>
<p>The expected output should resemble the following tree structure:</p>
<div>
<pre class="lang-js"><code>const TREE_DATA: Node[] = [
// Tree data sample...
];
Here is the link to the Stackblitz demo showcasing my attempts: https://stackblitz.com/edit/angular-h3btn5?file=src/app/tree-flat-overview-example.ts. I have been trying for days with no success. Any help would be greatly appreciated. Thank you!