advancedTree Memory

advancedTree Memory is a useful feature when you need to repopulate the tree after some external manipulation and you need it to remain at its current state of opened and closed nodes. For instance, if a advancedTree instance is populated with XML sent from a server, the user manipulates the nodes in the component, the XML is sent to the server for modification, then the component needs to be refreshed with the result, ideally you would want the tree to remain in its current visual state, which means nodes that are opened would remain open and nodes that are closed would remain closed. This can be accomplished by using the memory facility.

This functionality is only useful when the XML you are repopulating the tree with is the same form as the XML previously displayed in the tree. This is because the memory facility works by storing the levels and indices of the current nodes and attempting to reopen the nodes to the same state when then tree is refreshed with new XML. If the XML is different, then the memory fails.

The basic steps, which are elaborated upon below, are that the tree is "asked" for its current state, its memory is set to this state, then the tree is repopulated with new data. The tree will then attempt to apply its memory to the new data, opening the necessary nodes to reach the same visual state.
  1. Set a advancedTree instance's treeMemory property to be a string (this string will later be used as the name of the variable storing the memory).
  2. // tree's memory is set to be looked for in the variable "currentState"
    tree.treeMemory = "currentState";

  3. Assign the advancedTree instance's current state to the variable whose name was specified in the previous step.
  4. // tree's current state is stored in variable on tree's parent timeline
    currentState = tree.memory;

  5. Repopulate the advancedTree instance with new data. If the XML is similar enough, the visual state will be maintained.
  6. // tree is repopulated with new data and refreshed
    tree.populate(newXML);
    tree.refresh();