This is a search result. You cannot to get an access directly. It works like in jQuery: find some node (via Query) and do some action with the found node(s).
Methods which retruns this API:
Methods
find
Description: Finds nodes by specified
Arguments:
query:
Returns:
Usage:
// let's find the first child node of 'Awesome Node' which has state 'checked'
this.api
.find({text: 'Awesome Node'})
.find({ checked: true })
findAll
Description: Similar to find method. But it returns all found nodes.
Arguments:
Returns:
Usage:
// let's find all child nodes of 'Awesome Node' which has state 'checked'
this.api
.find({text: 'Awesome Node'})
.findAll({ checked: true })
remove
Description: Removes matched node.
Returns:
TreeNode
TreeNode[]
null
Usage:
this.api.selected().remove()
// how to get null?
this.api.find('not_existed_node').remove()
empty
Returns:
boolean
null
Usage:
this.api.find({ selected: true }).empty()
select
Description: Selects matched node.
Arguments:
extendSelection: boolean not required. For multiple mode adds the matched node to the list of selected items (it's like a selecting node via Ctrl)
expandOnSelect boolean, not required. select method will try to read this property from the tree props if expandOnSelect argument is not pass
Description: It is getter/setter for the data property of the node.
Arguments:
key: string | object
value : any (not required)
Returns:
undefined
data object
TreeNode
Usage:
// tree data
const data = [
{ text: 'Item 1', data: { isSuper: true } },
{ text: 'Item 2' },
{ text: 'Item 3' }
]
// it will find the first item (!)
this.api.find(/Item/).data('isSuper', false)
// or
this.api.find(/Item/).data({ isSuper: false }) // overrides the whole object
// return a value: value (false)
this.api.find(/Item/).data('isSuper')
// get full data object: { isSuper: false }
this.api.find(/Item/).data()
// setter: return NodeAPI
this.api.find(/Item/).data({ isSuper2: false })
// this.api.find(/Item/).data() will return { isSuper: false, isSuper2: false }
// as you can see it's possible you use API after setting the data
this.api.find(/Item/)
.data('isSuper2', 'string')
.expand()
How to set/get data for multiple nodes?
// set isSuper === false for nodes: `Item 2` and `Item 3`
this.api.findAll(/Item (2|3)/).data({ myProp: false })
// Get data for multiple nodes. It will return an array
this.api.findAll(/Item/).data('myProp')
// result will be: [undefined, false, false]
Description: Inserts nodes to the end of the matched node
Arguments:
nodes: string | object | Promise
Returns:
Promiselike<TreeNode[]> added nodes (always an array)
Usage:
const appendedNodes = this.api.find('Item 1').append(
['Item 1.1.', 'Item 1.2'], // nodes can be as string
{ expand: true } // expand node with text 'Item 1' (if node was found)
)
this.api.find({ selected: true }).append(
[
{ text: 'Selected children 1', disabled: true },
{ text: 'Selected children 2' }
]
)
// it also can be a function, but it must return a Promise
this.api.find('Selected children 2').append(
(node) => {
// node.text === 'Selected children 2'
return fetch(`/api?childName=${node.text}`)
.then(response => response.json())
}
)
prepend
Description: This method is similar to append. But nodes inserting to the beginning of children list. (well ... you know, as well as jQuery :) )