Most efficient way to rebuild a tree structure from data
- by Ahsan
Have a question on recursively populating JsTree using the .NET wrapper available via NuGet. Any help would be greatly appreciated.
the .NET class JsTree3Node has a property named Children which holds a list of JsTree3Nodes, and the pre-existing table which contains the node structure looks like this
NodeId ParentNodeId Data AbsolutePath
1 NULL News /News
2 1 Financial /News/Financial
3 2 StockMarket /News/Financial/StockMarket
I have a EF data context from the the database, so my code currently looks like this.
var parentNode = new JsTree3Node(Guid.NewGuid().ToString());
foreach(var nodeItem in context.Nodes)
{
parentNode.Children.Add(nodeItem.Data);
// What is the most efficient logic to do this recursively?
}
as the inline comment says in the above code, what would be the most efficient way to load the JStree data on to the parentNode object.
I can change the existing node table to suite the logic so feel free to suggest any changes to improve performance.