onItemsEvents([callback], [remove])
Class: Tree.
Description:
Gets, registers or unregisters an event handler function for events triggered by adding, removing, updating items and when the Tree structure is changed.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
|
|
function |
The event handler function. Receives an event object. |
|
|
|
boolean |
false |
Set to |
Returns:
When called without parameters, an array of handler functions is returned, otherwise this Tree component is returned for method chaining.
Type: Array.<function()> | Tree
Examples:
Event object format:
Object {
target: Tree, // The component that triggered the event
type: string, // "add", "update", "remove", or "restructure".
items: object[], // Items effected by the action that triggered the event
interactive: boolean // Only when type is "update". Indicates if the update was made by the user interacting with the item in GUI. `false` when updated programmatically.
}
Registering an event handler:
tree.onItemsEvents(e=>{alert(e.type);}); // shows the event type in a new message dialog window
Unregistering all registered event handlers:
let _handlers = tree.onItemsEvents(); // gets all handlers
for(let handler of _handlers) tree.onItemsEvents(handler, false); // unregisters each handler
