Instead of looking down the node tree with findAll
I’m trying to look up to see if any parent’s parents have a certain name
. Is there an existing way to do that?
There isn’t a convenience method in the API for that AFAIK, but you can get the parent
of a node (if it exists) and then the parent
of that node (again, if it exists) to check its name. Sort of a kludgy recursion function but you could write it that way.
Thanks, yes, I figured that’d be the only way. This is what I threw together, seems to be working the way I wanted:
const parentNameIncludes = (node, string) => {
if (node.type === 'PAGE') {
return false;
}
if (node.parent.name.includes(string)) {
return true;
} else {
parentNameIncludes(node.parent, string);
}
};
1 Like