<tree>
A tree control.

JavaScript: lz.tree
extends <basetree> » <basecomponent> » <view> » <node> » lz.Eventable »

A tree provides a hierarchical view of data. Each node is represented by an expander resource, an icon resource, and a label. A tree can be specified lexically or through data replication .

When the tree expands recursively, the datapath must be a relative reference to the dataset. If an absolute refrence is used, the same nodes would be selected over and over forever, resulting in and endless loop. For example, this will hang in an endless loop:

                      <dataset name="navdata">
                      <navmenu>
                      <section />
                      </navmenu>
                      </dataset>
                      
                      
                      <view x="10" y="10" layout="axis: x; spacing: 10">
                      <tree width="160" height="20" datapath="navdata:/navmenu" />
                      </view>
                  

It needs to be rewritten to have a relative datapath in the recursively expanding tree node.

                      <tree width="160" height="20" datapath="navdata:/navmenu">
                      <tree width="160" height="20" datapath="*" />
                      </tree>
                  

Each resource, if specified, should have three states. The expander resource should have an open (frame 1), closed (frame 2), and transparent (frame 3) state. The icon resource should have similar frames. See the default resources in tree as an example.

Example 64. A lexical tree and a data replicated tree

<canvas height="250">
              <include href="lz/tree.lzx"/>

              <dataset name="ancestors">
              <hobbit name="Frodo">
              <hobbit name="Drogo">
              <hobbit name="Fosco" grandparent="true"/>
              <hobbit name="Bolger, Ruby" grandparent="true"/>
              </hobbit>
              <hobbit name="Brandybuck, Primula">
              <hobbit name="Brandybuck, Gorbadoc" grandparent="true"/>
              <hobbit name="Took, Mirabella" grandparent="true"/>
              </hobbit>
              </hobbit>
              </dataset>

              <view x="20" y="20" layout="axis: x; spacing: 10">
              <!-- declared tree -->
              <view width="200" height="200">
              <tree open="true" text="valuemeal">
              <tree text="fries" isleaf="true"/>
              <tree open="true" text="drink">
              <tree text="cola" isleaf="true"/>
              </tree>
              <tree open="true" text="burger">
              <tree text="patty" isleaf="true"/>
              <tree text="lettuce" isleaf="true"/>
              <tree text="onions" isleaf="true"/>
              <tree text="buns" isleaf="true"/>
              </tree>
              </tree>
              </view>
              
              <!-- data replicated tree -->
              <view width="200" height="200">
              <tree datapath="ancestors:/" icon="null" showroot="false">
              <tree datapath="*" icon="null" text="$path{'@name'}" isleaf="$path{'@grandparent'}"/>
              </tree>
              </view>
              </view>
              </canvas>

Attributes

Name (CSS property) Type (tag) Type (js) Default Category
expander string String lztree_arrow_rsc initialize-only
  The resource for the expanding icon: frame 1 (closed), frame 2 (opened), frame 3 (leaf). Default is lztree_arrow_rsc defined in lz/tree.lzx.
icon string String lztree_folder_rsc initialize-only
  The resource for the item icon: frame 1 (closed), frame 2 (opened), frame 3 (leaf) Default is lztree_folder_rsc defined in lz/tree.lzx.

Methods

toggleOpenAndFocus()
tree.toggleOpenAndFocus();
Focus the tree and toggle open, if this tree is not a leaf and is not being multiselected.

Methods inherited from lz.Eventable

destroy, setAttribute

Events

Name Description
onactivate Double-clicking on the icon or text triggers this event.
onclick Clicking on the icon or text triggers this event.

Events inherited from <node>

onconstruct, ondata, oninit

Events inherited from lz.Eventable

ondestroy