I have an object called tree with an items property, which recursively contains more items, shown with the types below.
type Tree = { items: Item[] }
type Item = { base: Base; items: Item[] }
type Base = { category: string }
In Vue, I can create a new node or modify an existing one, but how can I assign this node to a place I choose?
setItems(emitted: Emitted) {
if (!this.tree) return;
this.searchandReplaceNode(emitted, this.tree.items);
console.log(this.tree.items)
},
searchandReplaceNode(emitted: Emitted, treeItems: Item[]) {
let currentNode = treeItems;
if (emitted.levels.length > 0) {
console.log("searching " + emitted.levels[0]);
//console.log(items);
currentNode = treeItems[emitted.levels[0]].items;
emitted.levels.shift();
console.log("remaining levels: " + emitted.levels);
this.searchandReplaceNode(emitted, currentNode);
} else {
console.log("levels consumed. assign emitted items to current node");
currentNode = emitted.items;
}
},
I have tried to use a level array, that tells me at what index to go deeper at each level.
Ultimately, I can get currentNode to be what I want, but I cannot get the relevant node in this.tree to be what I want.