Tree¶

   var tree = contrib.tree({fg: 'green'})
   //allow control the table with the keyboard
   tree.focus()
   tree.on('select',function(node){
     if (node.myCustomProperty){
       console.log(node.myCustomProperty);
     }
     console.log(node.name);
   }
   // you can specify a name property at root level to display root
   tree.setData(
   { extended: true
   , children:
     {
       'Fruit':
       { children:
         { 'Banana': {}
         , 'Apple': {}
         , 'Cherry': {}
         , 'Exotics': {
             children:
             { 'Mango': {}
             , 'Papaya': {}
             , 'Kiwi': { name: 'Kiwi (not the bird!)', myCustomProperty: "hairy fruit" }
             }}
         , 'Pear': {}}}
     , 'Vegetables':
       { children:
         { 'Peas': {}
         , 'Lettuce': {}
         , 'Pepper': {}}}}})
Options¶
- keys : Key to expand nodes. Default : ['enter','default']
- extended : Should nodes be extended/generated by default? Be careful with this setting when using a callback function. Default : false
- template :
- extend : Suffix "icon" for closed node. Default : '[+]'
- retract : Suffix "icon" for opened node. Default : '[-]'
- lines : Show lines in tree. Default : true
Nodes¶
Every node is a hash and it can have custom properties that can be used in "select" event callback. However, there are several special keys :
- name
- Type : string
- Desc : Node name
- If the node isn't the root and you don't specify the name, will be set to hash key
- Example : { name: 'Fruit'}
- children
- Type : hashorfunction(node){ return children }
- Desc : Node children.
- The function must return a hash that could have been used as children property
- If you use a function, the result will be stored in node.childrenContentandchildren
- Example :- Hash : {'Fruit':{ name: 'Fruit', children:{ 'Banana': {}, 'Cherry': {}}}}
- Function : see examples/explorer.js
 
- Hash : 
- childrenContent
- Type : hash
- Desc : Children content for internal usage DO NOT MODIFY
- If node.childrenis a hash,node.children===node.childrenContent
- If node.childrenis a function, it's used to store thenode.children()result
- You can read this property, but you should never write it.
- Usually this will be used to check if(node.childrenContent)in yournode.childrenfunction to generate children only once
- extended
- Type : boolean
- Desc : Determine if this node is extended
- No effect when the node have no child
- Default value for each node will be treeInstance.options.extendedif the nodeextendedoption is not set
- Example : {'Fruit':{ name: 'Fruit', extended: true, children:{ 'Banana': {}, 'Cherry': {}}}}
  Last update: February 22, 2020