Basic
Introducing
API provides a set of functions for advanced work with the tree: add/remove tree node, searching, changing state and so on.
It is divided into 2 parts for several reasons:
for reducing the weight of the component
a separate API has more features that are not very often needed in the work
Connection
The connection of the API is very easy. The component has a property onReady
. It calls right after componentDidMount
call. The API object is passed as the first argument to the onReady
function.
Methods
Most methods accept a Query argument. Full description: Query
find
Description: Finds nodes by specified Query
Arguments:
query
: Query
Returns:
TreeNode
null
if node is not found
Usage:
findAll
Description: Similar to
find
method. But it returns all found nodes.Arguments:
query
: Query
Returns:
Array<TreeNode>
Usage:
selected
Description: Returns selected nodes. Simple.
Returns: Result can be different depends on mode (multiple or single). See Component props
Single mode:
TreeNode
ornull
Multiple mode: array of
TreeNode
. It will be always an array.
Usage:
Single mode:
Multiple mode:
For a tree in multi-selection mode the selected method returns always an array. It does not matter if the selected nodes or not.
checked
Description: For
checkable
mode the library will combine checked nodes into an array. There are different ways to select "checked" nodes by usingvalueConsistsOf
argument.ALL
(default) it will gather all "checked" nodesBRANCH
if node has children and it is checked (and all of the children nodes are checked) then all children nodes will be excluded from the resultLEAF
returns nodes which doesn't has children nodesWITH_INDETERMINATE
the same asALL
plus indeterminate nodes
Arguments:
valueConsistsOf
: 'ALL' | 'BRANCH' | 'LEAF' | 'WITH_INDETERMINATE'showDisabled
: boolean (default false)
Returns:
Array<TreeNode>
Usage:
set
It is not recommended to use this method.
Description: Set any property to node. This method use
find
method from the API. So it will apply changes only for the first match.Arguments:
criteria
Find criteriapropName
: node of a property (ex: expanded, disabled and so on)propValue
Returns:
boolean
Usage:
To apply changes for all matches use next snippet:
data
You can store here whatever you want.
Description: It is getter/setter for the
data
property of the node.Arguments:
query
: Querykey
: string | objectvalue
: any (not required)
Returns:
undefined
data object
TreeNode
Usage:
This method has different return results
addClass
Description: It will add classNames for the node. This class will be added to the node with the class
.node-content
(check Node's structure)Arguments:
query
: QueryArray<className>
: string[]
Returns:
TreeNode
if node is foundnull
if node is not found
Usage:
removeClass
Description: The same behavior as
addClass
method, but it removes classNamesArguments:
query
: QueryArray<className>
: string[]
Returns:
TreeNode
if node is foundnull
if node is not found
Usage:
hasClass
Description: Checks if a node has a
className
Arguments:
query
: QueryclassName
: string
Returns:
boolean
Usage:
append
Description: Inserts nodes to the end of the matched node
Arguments:
query
: Querynodes
: string | object | Promiseopts
: Insertion options
Returns:
Promiselike<TreeNode[]>
added nodes (always an array)null
if node is not found
Usage:
prepend
Description: This method is similar to
append
. But nodes inserting to the beginning of children list. (well ... you know, as well as jQuery :) )Example:
before
Description: This method is similar to
append
. But nodes inserting before matched node.Example:
after
Description: This method is similar to
append
. But nodes inserting after matched node.
remove
Description: It removes matched node.
Arguments:
query
: Query
Returns:
TreeNode
removed nodenull
if node is not found
Usage:
uncheckAll
Description: Set for all checked nodes unchecked states
unselectAll
Description: Removes selection for all selected nodes
toArray
Description: Returns list of nodes.
Last updated