Tree Class

Used to create a hierarchical tree control with nodes and leaves. The nodes and leaves are "left-justified". Root nodes appear on the left and nested elements appear below and to the right of the parent nodes.

Constructors

Tree( parent, config )
Used to instantiate this class
parentDOM element in which to render this component
configConfiguration settings (optional). See config options for more information.

Config Options

style
Style for individual elements within the component. The nodes and leaves in the tree are constructed using "ul" and "li" elements. Note that unlike most of the other components, you should provide CSS class names nodes, leaves, and path.

Events

onClick( item )
Called whenever an item is clicked in the tree.
itemThe item that was clicked. See getItem() for more information.
onExpand( item )
Called whenever a node is expanded in the tree.
itemThe node that was expanded. See getItem() for more information.
onCollapse( item )
Called whenever a node is collapsed in the tree.
itemThe node that was collapsed. See getItem() for more information.

Public Methods

clear( )
Used to remove all the nodes in the tree
addNodes( nodes, expandAll )
Used to add nodes to the tree.
nodes
expandAllIf true, will render all the nodes and leaves. Default is false.
getItem( path )
Returns a simple json object used to represent an item in the tree for a given path.
  • type: Item type (e.g. "node" or "leaf")
  • name: Text/Label associated with the item
  • el: DOM element used to render the item(e.g. "li")
pathPath to an element in the tree, Accepts either a string array or a "/" delimited string.
show( item )
Used to expand a given item in the tree. If no item is specified, then the
hide( item )
getPath( item )
Returns an array of parent nodes that form a path to the given item.