new TreeNode()
A class which provides TreeNode,
TreeNode is the node of DOM tree, so TreeNode provides APIs that are related tree.
- Since:
-
- 2.0.0
Example
var TreeNode = caph.require('collection.TreeNode'); var treenode = new TreeNode;
Methods
-
addChild(node, option) → {caph.collection.TreeNode}
-
Adds child node
Parameters:
Name Type Argument Description node
caph.collection.TreeNode | Array.<TreeNode> TreeNode object will be the child, It can be Array or single Node object
option
Object <optional>
Option
Properties
Name Type Argument Description callback
callbackOperationSucceeded <optional>
the given function will be called when the given node has been truly added into its children.
- Since:
-
- 2.0.0
Returns:
Returns caph.collection.TreeNode
Example
var TreeNode = caph.require('collection.TreeNode'); var child = new TreeNode; var parent = new TreeNode; parent.addChild(child);
-
addTo(node) → {caph.collection.TreeNode}
-
Adds itself to given node's child
Parameters:
Name Type Description node
caph.collection.TreeNode TreeNode object will be the parent
- Since:
-
- 2.0.0
Returns:
Returns caph.collection.TreeNode
Example
var TreeNode = caph.require('collection.TreeNode'); var child = new TreeNode; var parent = new TreeNode; child.addTo(parent);
-
destroy()
-
Destroys itself and all its children,
which makes them available for garbage collection and means they can't be reused.- Since:
-
- 2.0.0
Example
var TreeNode = caph.require('collection.TreeNode'); var destroyNode = new TreeNode; var parent = new TreeNode; parent.addChild(destroyNode); parent.destroy(); //all of children are removed and destroyed
-
getChildren() → {Array.<TreeNode>}
-
Returns children
- Since:
-
- 2.0.0
Returns:
Returns array of children
- Type
- Array.<TreeNode>
Example
var TreeNode = caph.require('collection.TreeNode'); var parent = new TreeNode; var child = new TreeNode; child.addTo(parent); var childrenOfParent = parent.getChildren(); //child will be returned
-
getParent() → {caph.collection.TreeNode|null}
-
Returns parent
- Since:
-
- 2.0.0
Returns:
Return whether caph.collection.TreeNode or null
- Type
- caph.collection.TreeNode | null
Example
var TreeNode = caph.require('collection.TreeNode'); var child = new TreeNode; var parent = new TreeNode; child.attTo(parent); var parentOfchild = child.getParent(); //parent will be returned
-
getRoot() → {caph.collection.TreeNode}
-
Returns a root node through searching parent nodes. It's recommended to cache the returned value if you need to get it several times.
- Since:
-
- 2.0.0
Returns:
A root node of the tree containing this node.
Example
var TreeNode = caph.require('collection.TreeNode'); var root, parent = new TreeNode, child1 = new TreeNode, child2 = new TreeNode; parent.addChild(child1).addChild(child2); root = child2.getRoot();
-
getSiblings() → {Array.<TreeNode>}
-
Returns siblings
- Since:
-
- 2.0.0
Returns:
Returns array of siblings
- Type
- Array.<TreeNode>
Example
var TreeNode = caph.require('collection.TreeNode'); var parent = new TreeNode; var child1 = new TreeNode; var child2 = new TreeNode; child1.addTo(parent); child2.addTo(parent); var siblingOfChild1 = child1.getSiblings(); //child will be returned
-
hasChild() → {Boolean}
-
Returns whether or not any children exist
- Since:
-
- 2.0.0
Returns:
Returns true or false based on that a node has child or not
- Type
- Boolean
Example
var TreeNode = caph.require('collection.TreeNode'); var parent = new TreeNode; var child1 = new TreeNode; var child2 = new TreeNode; child1.addTo(parent); child2.addTo(parent); var has = parent.hasChild(); //true will be returned
-
removeChild(node, option) → {caph.collection.TreeNode}
-
Removes node in children if that node is child node, the removed node will still be reusable until destroying node.
If second parameter is TRUE, the node will be destroyed.Parameters:
Name Type Argument Description node
caph.collection.TreeNode | Array.<TreeNode> Node to remove.
option
Object <optional>
Option
Properties
Name Type Argument Description destroy
Boolean <optional>
Determines whether or not to destroy the given node.
Once the given node and its children is destroyed, it can be included in garbage collection.callback
callbackOperationSucceeded <optional>
the given function will be called when the given node has been truly removed from its parent.
- Since:
-
- 2.0.0
Returns:
Returns caph.collection.TreeNode
Example
var TreeNode = caph.require('collection.TreeNode'); var child = new TreeNode; var parent = new TreeNode; parent.addChild(child); parent.removeChild(child);
-
removeFromParent() → {caph.collection.TreeNode}
-
Removes itself from TreeNode chain
- Since:
-
- 2.0.0
Returns:
Returns caph.collection.TreeNode
Example
var TreeNode = caph.require('collection.TreeNode'); var child = new TreeNode; var parent = new TreeNode; child.addTo(parent); child.removeFromParent();