I want to find the top-level parent (on the tree) of the current node.
I have the following code:
expandParents(node: any) {
const parent = node.data.x.parent;
if (!!parent && this.getLevel(parent) > 0) {
this.expandParents(parent);
} else if (!!parent && this.getLevel(parent) === 0) {
console.log('1. ', parent);
return parent;
}
}
getTopLevelParent(node: T) {
const topLevelParent = this.expandParents(node);
console.log('2. ', topLevelParent);
return topLevelParent;
}
Below, is what console.log prints:
1. DynamicFlatNode {data: {…}}
2. undefined
Why console.log('2. ', topLevelParent); always returns undefined?