-
Notifications
You must be signed in to change notification settings - Fork 214
Show until specific level in tree #244
New issue
Have a question about this project? No Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “No Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? No Sign in to your account
Comments
To be clear, are you looking for something to expand all of the nodes until the third level? This is a reasonable enough request, but it can be done through the I can potentially add a utility function to help set that initial state. |
yes, i want expand all of the nodes until the third level :) |
For the interim, you can do something like the following. Note that the first level starts with 0: function expandNodesToLevel(nodes, targetLevel, currentLevel = 0) {
if (currentLevel > targetLevel) {
return [];
}
let expanded = [];
nodes.forEach((node) => {
expanded.push(node.value);
if (node.children) {
expanded = [...expanded, ...expandNodesToLevel(node.children, targetLevel, currentLevel + 1)];
}
});
return expanded;
} For the initial state, you would do something like See the following example that expands the tree to the second level. |
it works perfect! |
Please include a clear and concise description of the feature or enhancement you would like to have added to the project.
Hi, is there a way to show until specific leven in the tree? For example, i have an array with four levels from the API, but i just want to show until the third level. Is that possible?
The text was updated successfully, but these errors were encountered: