vanillatree
Standalone tree view library
Usage
For CJS env run npm install --save vanillatree
:
const VanillaTree = ;
// treeElement is selector or HTML node, options is optionalconst tree = treeElement options;
Options
placeholder
(string) -- shows if none of leafs is added (optional)contextmenu
(array) -- contextual menu items (optional)
Examples
const tree = '.my-selector' placeholder: 'No leaf is added yet' contextmenu: label: 'Label 1' { // someAction } label: 'Label 2' { // someAction } ;
Methods
add(options)
-- Adds a leaf.id
option is optionalmove(id, parentId)
-- Moves a leaf to another parentremove(id)
-- Removes a leaf with given idopen(id)
-- Expands child treeclose(id)
-- Closes child treetoggle(id)
-- Expands or closes child tree depending on current stateselect(id)
-- Selects a leaf with given id
Examples
tree; tree; tree;
Events
VanillaTree
uses dispatchEvent for events triggering. Each event is cancelable and bubbles up through the DOM. An id of a target element is placed at evt.detail
object.
A list of possible events:
vtree-add
vtree-move
vtree-remove
vtree-open
vtree-close
vtree-select
Examples
treeElement; treeElement; treeElement;
Image sprite is the part of JSTree project