Hello,
Is there a way to add a node to another node while preserving all the children of the node being added?
In javascript.
Hi,
I think you are looking for something like this:
function AddChildNodesRecursive(childNode, parentNode) {
var newChild = parentNode.addChild(childNode.getText());
if (childNode.hasChildren()) {
var children = childNode.getChildNodes();
for (c in children) {
var childSubNode = children[ c ];
AddChildNodesRecursive(childSubNode, newChild);
}
Matthew,
I thought I tackled a similar problem a while back. I have a system built around the structure of the Infragistics demos. That is, a WebTree on the left for navigation, a title bar, a footer, and a contents page.
Basically, the contents page is generally a grid that allows the customer to then select a person or a piece of inventory or whatever.
However, one of the options I need is to allow the operator to right-click on a grid selector and select 'Move to Folder' to move the individual to another tree node. Since the content page is in a different frame (and is a different asp.net page) I wanted to popup a form, populate the WebTree on that form with the contents of the WebTree I use as a navigation tool - the one in the left frame.
I 'accomplished' this by saving the WebTree in the left menu frame to a Session variable. I then retrieved that WebTree object in the popup form and used the .AddRange() to quickly populate the tree on the popup form. It all looked good, seemed to work. However, I have used the same concept in a new more complex tree and it flubs. Basically, if the customer selects a node at the same level as the initial selection than the 'Selected Node' remains the initial node. If, however, the customer selects a node outside of the initial node's siblings it seems to work a bit better.
My guess is that restoring a tree from a Session variable may not be as reliable as I thought. And, AddRange() may be doing some whoop-di-da for performance reasons and not really fully adding all the nodes - but, instead keying on the sibling nodes. More useful for an On Demand load.
Clear as mud, eh.
Confusing.
As an alternative, could I use the tree and nodes saved in the session to initiate recursive Add()s similar to the above? Or, is saving a WebTree to a session unreliable?
Hello Mr. Kraft,
Thank you for replying to the post so quicky and for the help.