Class: TreeNodes

TreeNodes(tree, array, opts) → {TreeNodes}

An Array-like collection of TreeNodes. Note: Due to issue in many javascript environments, native objects are problematic to extend correctly so we mimic it, not actually extend it.

Constructor

new TreeNodes(tree, array, opts) → {TreeNodes}

Parameters:
Name Type Description
tree InspireTree Context tree.
array array Array of TreeNode objects.
opts object Configuration object.
Source:
Returns:
Collection of TreeNode
Type
TreeNodes

Methods

addNode(object) → {TreeNode}

Adds a new node. If a sort method is configured, the node will be added in the appropriate order.
Parameters:
Name Type Description
object object Node
Source:
Returns:
Node object.
Type
TreeNode

available(full) → {TreeNodes}

Query for all available nodes.
Parameters:
Name Type Description
full boolean Retain full hiearchy.
Source:
Returns:
Array of node objects.
Type
TreeNodes

blur() → {TreeNodes}

Blur nodes.
Source:
Returns:
Array of node objects.
Type
TreeNodes

blurDeep() → {TreeNodes}

Blur (deeply) all nodes.
Source:
Returns:
Array of node objects.
Type
TreeNodes

checked(full) → {TreeNodes}

Query for all checked nodes.
Parameters:
Name Type Description
full boolean Retain full hiearchy.
Source:
Returns:
Array of node objects.
Type
TreeNodes

clean() → {TreeNodes}

Clean nodes.
Source:
Returns:
Array of node objects.
Type
TreeNodes

clone() → {TreeNodes}

Clones (deeply) the array of nodes. Note: Cloning will *not* clone the context pointer.
Source:
Returns:
Array of cloned nodes.
Type
TreeNodes

collapse() → {TreeNodes}

Collapse nodes.
Source:
Returns:
Array of node objects.
Type
TreeNodes

collapsed(full) → {TreeNodes}

Query for all collapsed nodes.
Parameters:
Name Type Description
full boolean Retain full hiearchy.
Source:
Returns:
Array of node objects.
Type
TreeNodes

collapseDeep() → {TreeNodes}

Collapse (deeply) all children.
Source:
Returns:
Array of node objects.
Type
TreeNodes

concat(nodes) → {TreeNodes}

Concat multiple TreeNodes arrays.
Parameters:
Name Type Description
nodes TreeNodes Array of nodes.
Source:
Returns:
Resulting node array.
Type
TreeNodes

context() → {TreeNode|object}

Get the context of this collection. If a collection of children, context is the parent node. Otherwise the context is the tree itself.
Source:
Returns:
Node object or tree instance.
Type
TreeNode | object

copy(dest, hierarchy, includeState) → {object}

Copy nodes to another tree instance.
Parameters:
Name Type Description
dest object Destination Inspire Tree.
hierarchy boolean Include necessary ancestors to match hierarchy.
includeState boolean Include itree.state object.
Source:
Returns:
Methods to perform action on copied nodes.
Type
object

deepest() → {TreeNodes}

Return deepest nodes.
Source:
Returns:
Array of node objects.
Type
TreeNodes

deselect() → {TreeNodes}

Deselect nodes.
Source:
Returns:
Array of node objects.
Type
TreeNodes

deselectDeep() → {TreeNodes}

Deselect (deeply) all nodes.
Source:
Returns:
Array of node objects.
Type
TreeNodes

each(iteratee) → {TreeNodes}

Iterate each TreeNode.
Parameters:
Name Type Description
iteratee function Iteratee invoke for each node.
Source:
Returns:
Array of node objects.
Type
TreeNodes

editable(full) → {TreeNodes}

Query for all editable nodes.
Parameters:
Name Type Description
full boolean Retain full hiearchy.
Source:
Returns:
Array of node objects.
Type
TreeNodes

editing(full) → {TreeNodes}

Query for all nodes in editing mode.
Parameters:
Name Type Description
full boolean Retain full hiearchy.
Source:
Returns:
Array of node objects.
Type
TreeNodes

expand() → {TreeNodes}

Expand nodes.
Source:
Returns:
Array of node objects.
Type
TreeNodes

expandDeep() → {Promise.<TreeNodes>}

Expand (deeply) all nodes.
Source:
Returns:
Promise resolved when all children have loaded and expanded.
Type
Promise.<TreeNodes>

expanded(full) → {TreeNodes}

Query for all expanded nodes.
Parameters:
Name Type Description
full boolean Retain full hiearchy.
Source:
Returns:
Array of node objects.
Type
TreeNodes

expandParents() → {TreeNodes}

Expand parents.
Source:
Returns:
Array of node objects.
Type
TreeNodes

extract(predicate) → {TreeNodes}

Clone a hierarchy of all nodes matching a predicate. Because it filters deeply, we must clone all nodes so that we don't affect the actual node array.
Parameters:
Name Type Description
predicate string | function State flag or custom function.
Source:
Returns:
Array of node objects.
Type
TreeNodes

filterBy(predicate) → {TreeNodes}

Filter all nodes matching the given predicate.
Parameters:
Name Type Description
predicate string | function State flag or custom function.
Source:
Returns:
Array of node objects.
Type
TreeNodes

find(predicate) → {TreeNode}

Returns the first node matching predicate.
Parameters:
Name Type Description
predicate function Predicate function, accepts a single node and returns a boolean.
Source:
Returns:
First matching TreeNode, or undefined.
Type
TreeNode

first(predicate) → {TreeNode}

Returns the first shallow node matching predicate.
Parameters:
Name Type Description
predicate function Predicate function, accepts a single node and returns a boolean.
Source:
Returns:
First matching TreeNode, or undefined.
Type
TreeNode

flatten(predicate) → {TreeNodes}

Flatten and get only node(s) matching the expected state or predicate function.
Parameters:
Name Type Description
predicate string | function State property or custom function.
Source:
Returns:
Flat array of matching nodes.
Type
TreeNodes

focused(full) → {TreeNodes}

Query for all focused nodes.
Parameters:
Name Type Description
full boolean Retain full hiearchy.
Source:
Returns:
Array of node objects.
Type
TreeNodes

forEach(iteratee) → {TreeNodes}

Iterate each TreeNode.
Parameters:
Name Type Description
iteratee function Iteratee invoke for each node.
Source:
Returns:
Array of node objects.
Type
TreeNodes

get(index) → {TreeNode}

Get a specific node by its index, or undefined if it doesn't exist.
Parameters:
Name Type Description
index int Numeric index of requested node.
Source:
Returns:
Node object. Undefined if invalid index.
Type
TreeNode

hidden(full) → {TreeNodes}

Query for all hidden nodes.
Parameters:
Name Type Description
full boolean Retain full hiearchy.
Source:
Returns:
Array of node objects.
Type
TreeNodes

hide() → {TreeNodes}

Hide nodes.
Source:
Returns:
Array of node objects.
Type
TreeNodes

hideDeep() → {TreeNodes}

Hide (deeply) all nodes.
Source:
Returns:
Array of node objects.
Type
TreeNodes

indeterminate(full) → {TreeNodes}

Query for all indeterminate nodes.
Parameters:
Name Type Description
full boolean Retain full hiearchy.
Source:
Returns:
Array of node objects.
Type
TreeNodes

insertAt(index, object) → {TreeNode}

Insert a new node at a given position.
Parameters:
Name Type Description
index integer Index at which to insert the node.
object object Raw node object or TreeNode.
Source:
Returns:
Node object.
Type
TreeNode

invoke(methods, args) → {TreeNodes}

Invoke method(s) on each node.
Parameters:
Name Type Description
methods string | array Method name(s).
args array | Arguments Array of arguments to proxy.
Source:
Returns:
Array of node objects.
Type
TreeNodes

invokeDeep(methods, args) → {TreeNodes}

Invoke method(s) deeply.
Parameters:
Name Type Description
methods string | array Method name(s).
args array | Arguments Array of arguments to proxy.
Source:
Returns:
Array of node objects.
Type
TreeNodes

last(predicate) → {TreeNode}

Returns the last shallow node matching predicate.
Parameters:
Name Type Description
predicate function Predicate function, accepts a single node and returns a boolean.
Source:
Returns:
Last matching shallow TreeNode, or undefined.
Type
TreeNode

loading(full) → {TreeNodes}

Query for all nodes currently loading children.
Parameters:
Name Type Description
full boolean Retain full hiearchy.
Source:
Returns:
Array of node objects.
Type
TreeNodes

loadMore(event) → {Promise.<TreeNodes>}

Loads additional nodes for this context.
Parameters:
Name Type Description
event Event Click or scroll event if DOM interaction triggered this call.
Source:
Returns:
Resolves with request results.
Type
Promise.<TreeNodes>

matched(full) → {TreeNodes}

Query for all nodes matched in the last search.
Parameters:
Name Type Description
full boolean Retain full hiearchy.
Source:
Returns:
Array of node objects.
Type
TreeNodes

move(index, newIndex, target) → {TreeNode}

Move node at a given index to a new index.
Parameters:
Name Type Description
index int Current index.
newIndex int New index.
target TreeNodes Target TreeNodes array. Defaults to this.
Source:
Returns:
Node object.
Type
TreeNode

node(id) → {TreeNode}

Get a node.
Parameters:
Name Type Description
id string | number ID of node.
Source:
Returns:
Node object.
Type
TreeNode

nodes(refs) → {TreeNodes}

Get all nodes in a tree, or nodes for an array of IDs.
Parameters:
Name Type Description
refs array Array of ID references.
Source:
Returns:
Array of node objects.
Type
TreeNodes
Example
const all = tree.nodes()
const some = tree.nodes([1, 2, 3])

pagination() → {object}

Get the pagination.
Source:
Returns:
Pagination configuration object.
Type
object

pop() → {TreeNode}

Removes the last node.
Source:
Returns:
Last tree node.
Type
TreeNode

push(node) → {number}

Push a new TreeNode onto the collection.
Parameters:
Name Type Description
node TreeNode Node objext.
Source:
Returns:
The new length.
Type
number

recurseDown(iteratee) → {TreeNodes}

Iterate down all nodes and any children. Return false to stop execution.
Parameters:
Name Type Description
iteratee function Iteratee function.
Source:
Returns:
Resulting nodes.
Type
TreeNodes

remove(node) → {TreeNodes}

Remove a node.
Parameters:
Name Type Description
node TreeNode Node object.
Source:
Returns:
Resulting nodes.
Type
TreeNodes

removed(full) → {TreeNodes}

Query for all soft-removed nodes.
Parameters:
Name Type Description
full boolean Retain full hiearchy.
Source:
Returns:
Array of node objects.
Type
TreeNodes

restore() → {TreeNodes}

Restore nodes.
Source:
Returns:
Array of node objects.
Type
TreeNodes

restoreDeep() → {TreeNodes}

Restore (deeply) all nodes.
Source:
Returns:
Array of node objects.
Type
TreeNodes

select() → {TreeNodes}

Select nodes.
Source:
Returns:
Array of node objects.
Type
TreeNodes

selectable(full) → {TreeNodes}

Query for all selectable nodes.
Parameters:
Name Type Description
full boolean Retain full hiearchy.
Source:
Returns:
Array of node objects.
Type
TreeNodes

selectDeep() → {TreeNodes}

Select (deeply) all nodes.
Source:
Returns:
Array of node objects.
Type
TreeNodes

selected(full) → {TreeNodes}

Query for all selected nodes.
Parameters:
Name Type Description
full boolean Retain full hiearchy.
Source:
Returns:
Array of node objects.
Type
TreeNodes

shift(node) → {TreeNode}

Removes the first node.
Parameters:
Name Type Description
node TreeNode Node object.
Source:
Returns:
Node object.
Type
TreeNode

show() → {TreeNodes}

Show nodes.
Source:
Returns:
Array of node objects.
Type
TreeNodes

showDeep() → {TreeNodes}

Show (deeply) all nodes.
Source:
Returns:
Array of node objects.
Type
TreeNodes

softRemove() → {TreeNodes}

Soft-remove nodes.
Source:
Returns:
Array of node objects.
Type
TreeNodes

sortBy(sorter) → {TreeNodes}

Sorts all TreeNode objects in this collection. If no custom sorter given, the configured "sort" value will be used.
Parameters:
Name Type Description
sorter string | function Sort function or property name.
Source:
Returns:
Array of node objects.
Type
TreeNodes

sortDeep(comparator) → {TreeNodes}

Sorts (deeply) all nodes in this collection.
Parameters:
Name Type Description
comparator function [description]
Source:
Returns:
Array of node objects.
Type
TreeNodes

splice(start, deleteCount) → {array}

Changes array contents by removing existing nodes and/or adding new nodes.
Parameters:
Name Type Description
start number Start index.
deleteCount number Number of nodes to delete.
...nodes TreeNode One or more nodes.
Source:
Returns:
Array of deleted elements.
Type
array

state(name, newVal) → {TreeNodes}

Set nodes' state values.
Parameters:
Name Type Description
name string Property name.
newVal boolean New value, if setting.
Source:
Returns:
Array of node objects.
Type
TreeNodes

stateDeep(name, newVal) → {TreeNodes}

Set (deeply) nodes' state values.
Parameters:
Name Type Description
name string Property name.
newVal boolean New value, if setting.
Source:
Returns:
Array of node objects.
Type
TreeNodes

swap(node1, node2) → {TreeNodes}

Swaps two node positions.
Parameters:
Name Type Description
node1 TreeNode Node 1.
node2 TreeNode Node 2.
Source:
Returns:
Array of node objects.
Type
TreeNodes

toArray() → {array}

Get a native node Array.
Source:
Returns:
Array of node objects.
Type
array

tree() → {InspireTree}

Get the tree instance.
Source:
Returns:
Tree instance.
Type
InspireTree

unshift(node) → {number}

Adds a node to beginning of the collection.
Parameters:
Name Type Description
node TreeNode Node object.
Source:
Returns:
New length of collection.
Type
number

visible(full) → {TreeNodes}

Query for all visible nodes.
Parameters:
Name Type Description
full boolean Retain full hiearchy.
Source:
Returns:
Array of node objects.
Type
TreeNodes