.. _dijit/Tree-examples:
dijit.Tree examples
===================
:Status: Draft
:Version: 1.2
.. contents::
:depth: 3
Initialise the Tree after onLoad Event has Fired
------------------------------------------------
``New in 1.4`` The onLoad event is being introduced in Dojo release 1.4.
.. code-block :: javascript
:linenos:
var tree = dijit.byId('myTree');
// Connect to tree onLoad to do work once it has initialised
var tmph = dojo.connect(tree, 'onLoad', function() {
console.debug("tree onLoad here!");
dojo.disconnect(tmph);
// do work here
});
Expanding and Focusing tree nodes programatically
-------------------------------------------------
``New in 1.4``
``dijit.Tree`` in dojo 1.4 has a new 'path' attribute, which can be set with the usual ``tree.attr('path', thePath);`` syntax. It serves two purposes: to expand the tree up to the node in question, and to highlight that node.
.. cv-compound::
.. cv:: javascript
.. cv:: html
Highlight the node!
One problem with using 'path' is that you must know the full path to the node in your data your are trying to select.
The following example contains workaround code for this problem, as well as an example call to tree.attr('path'). If you already know the full path to the tree node you want to highlight, you can simply call tree.attr('path').
.. cv-compound::
.. cv:: javascript
.. cv:: html
Highlight the node!
How can I prevent expanding of nodes when clicking on them?
-----------------------------------------------------------
Simply set the ``openOnClick`` attribute to ``false``
.. cv-compound::
.. cv:: javascript
.. cv:: html
Example using Local Data and Markup
-----------------------------------------------------------
Most of the examples have used the same url:json source of the data for the store.
This example uses local data from a javascript object as the raw data.
In addition, _createTreeNode is overridden to allow HTML markup in the tree.
This is a hack, in the sense that the formatting may not be perfect for large (in pixels) elements.
But the tree will display and work properly regardless, and for simple markup, eg bold, it works great.
.. cv-compound::
.. cv:: javascript
.. cv:: html