Skip to content

Functions: Tree

Cheton Wu edited this page Apr 6, 2016 · 26 revisions

addChildNodeAt(newNode, index, parentNode)

Inserts a new child node to a parent node at the specified index.

  • If the parent is null or undefined, inserts the child at the specified index in the top-level.
  • If the parent has children, the method adds the child to it at the specified index.
  • If the parent does not have children, the method adds the child to the parent.
  • If the index value is greater than or equal to the number of children in the parent, the method adds the child at the end of the children.
Arguments
  1. newNode (Object): The new child node.
  2. index (number): The 0-based index of where to insert the child node. Defaults to 0 for negative index.
  3. parentNode (Node): The Node object that defines the parent node.
Returns

(boolean): Returns true on success, false otherwise.

Example

appendChildNode(newNode, parentNode)

Adds a node to the end of the list of children of a specified parent node.

  • If the parent is null or undefined, inserts the child at the specified index in the top-level.
  • If the parent has children, the method adds the child as the last child.
  • If the parent does not have children, the method adds the child to the parent.
Arguments
  1. newNode (Object): The new child node.
  2. parentNode (Node): The Node object that defines the parent node.
Returns

(boolean): Returns true on success, false otherwise.

Example

clear()

Clears the tree.

Example

closeNode(node)

Closes a node to hide its children.

Arguments
  1. node (Node): The Node object.
Returns

(boolean): Returns true on success, false otherwise.

Example

flattenChildNodes(parentNode)

Flattens all child nodes of a parent node.

Arguments
  1. parentNode (Node): The Node object that defines the parent node.
Returns

(Array): Returns an array of Node objects containing all the child nodes of the parent node.

Example

flattenNode(node)

Flattens a node.

Arguments
  1. node (Node): The Node object.
Returns

(Array): Returns a flattened list of Node objects.

Example

getChildNodes(parentNode)

Gets a list of child nodes.

Arguments
  1. parentNode (Node): The Node object that defines the parent node. If null or undefined, returns a list of top level nodes.
Returns

(Array): Returns an array of Node objects containing all the child nodes of the parent node.

Example

getNodeById(id)

Gets a node by its unique id. This assumes that you have given the nodes in the data a unique id.

Arguments
  1. id (number|string): An unique node id. A null value will be returned if the id doesn't match.
Returns

(Node): Returns a Node object that matches the id, null otherwise.

Example

getOpenNodes()

Gets an array of open nodes.

Returns

(Array): Returns an array of Node objects containing open nodes.

Example

getRootNode()

Returns

(Node): Returns the root node, or null if empty.

Example

getSelectedNode()

Returns

(Node): Returns the selected node, or null if not selected.

Example

insertNodeAfter(newNode, referenceNode)

Inserts the specified node after the reference node.

Arguments
  1. newNode (Object): The new sibling node.
  2. referenceNode (Node): The Node object that defines the reference node.
Returns

(boolean): Returns true on success, false otherwise.

Example

insertNodeBefore(newNode, referenceNode)

Inserts the specified node before the reference node.

Arguments
  1. newNode (Object): The new sibling node.
  2. referenceNode (Node): The Node object that defines the reference node.
Returns

(boolean): Returns true on success, false otherwise.

Example

loadData(data)

Loads data in the tree.

Arguments
  1. data (Object|Array): The data is an object or array of objects that defines the node.
Example

openNode(node)

Opens a node to display its children.

Arguments
  1. node (Node): The Node object.
Returns

(boolean): Returns true on success, false otherwise.

Example

removeChildNodes(parentNode)

Removes all child nodes from a parent node.

Arguments
  1. parentNode (Node): The Node object that defines the parent node.
Returns

(boolean): Returns true on success, false otherwise.

Example

removeNode(node)

Removes a node and all of its child nodes.

Arguments
  1. node (Node): The Node object.
Returns

(boolean): Returns true on success, false otherwise.

Example

scrollToNode(node)

Sets the current scroll position to this node.

Arguments
  1. node (Node): The Node object.
Returns

(number): Returns the vertical scroll position, or -1 on error.

Example

scrollTop(value)

Arguments
  1. value (number): An integer that indicates the new position to set the scroll bar to.
Returns

(number): Returns the vertical scroll position.

Example

selectNode(node)

Selects a node.

Arguments
  1. node (Node): The Node object. If null or undefined, deselects the current node.
Returns

(boolean): Returns true on success, false otherwise.

Example

toggleNode(node)

Toggles a node to display or hide its children.

Arguments
  1. node (Node): The Node object.
Example

toString(node)

Serializes the current state of a node to a JSON string.

Arguments
  1. node (Node): The Node object. If null, returns the whole tree.
Returns

(string): Returns a JSON string represented the tree.

Example

update()

Updates the tree.

Example

updateNode(node, data)

Updates the data of a node.

Arguments
  1. node (Node): The Node object.
  2. data (Object): The data object.
Example
Clone this wiki locally