Skip to content

Functions: Tree

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

Index


addChildNodes(newNodes, [index], [parentNode])

Adds an array of new child nodes to a parent node at the specified index.

Arguments
  1. newNodes (Array): An array of new child nodes.
  2. [index] (number): The 0-based index of where to insert the child node.
  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 new child 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, [options])

Closes a node to hide its children.

Arguments
  1. node (Node): The Node object.
  2. [options={}] (Object): The options object.
  3. [options.silent=false] (boolean): Sets true to prevent "closeNode" event from being triggered.
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

getNodeFromPoint(x, y)

Returns the node at the specified point. If the specified point is outside the visible bounds or either coordinate is negative, the result is null.

Arguments
  1. x (number): A horizontal position within the current viewport.
  2. y (number): A vertical position within the current viewport.
Returns

(Node): Returns a Node object under the given point.

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

getSelectedIndex()

Returns

(number): Returns the index of the selected node, or -1 if not selected.

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

moveNodeTo(node, parentNode, [index])

Moves a node from its current position to the new position.

Arguments
  1. node (Node): The Node object.
  2. parentNode (Node): The Node object that defines the parent node.
  3. [index] (number): The 0-based index of where to insert the child node.
Returns

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

Example

openNode(node, [options])

Opens a node to display its children.

Arguments
  1. node (Node): The Node object.
  2. [options={}] (Object): The options object.
  3. [options.silent=false] (boolean): Sets true to prevent "openNode" event from being triggered.
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

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

Example

scrollTop([value])

Arguments
  1. [value] (number): If the value is specified, indicates the new position to set the scroll bar to.
Returns

(number): Returns the vertical scroll position.

Example

selectNode(node, [options])

Selects a node.

Arguments
  1. node (Node): The Node object. If null or undefined, deselects the current node.
  2. [options={}] (Object): The options object.
  3. [options.autoScroll=true] (boolean): Sets true to automatically scroll to the selected node. Defaults to true.
  4. [options.silent=false] (boolean): Sets true to prevent "selectNode" event from being triggered. Defaults to false.
Returns

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

Example

swapNodes(node1, node2)

Swaps two nodes.

Arguments
  1. node1 (Node): The Node object.
  2. node2 (Node): The Node object.
Returns

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

Example

toggleNode(node, [options])

Toggles a node to display or hide its children.

Arguments
  1. node (Node): The Node object.
  2. [options={}] (Object): The options object.
  3. [options.silent=false] (boolean): Sets true to prevent "closeNode", "openNode", and "selectNode" events from being triggered.
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, [options])

Updates the data of a node.

Arguments
  1. node (Node): The Node object.
  2. data (Object): The data object.
  3. [options={}] (Object): The options object.
  4. [options.shallowRendering=false] (boolean): Sets true to render only the node without expanded child nodes.
Example
Clone this wiki locally