1

I have a dijit/Tree that works fine. However, I cannot figure out how to get the DOM node for a specific row from the id (the id in the store, not the DOM id).

Something like:

myTreeModel.getDomNodeById( id );

I am using dijit/Tree, dijit/tree/ObjectStoreModel and dojo/store/memoryStore.

Everything seems to be geared towards getting the store data but I want the to change the class on a dom node in response to events elsewhere in my application.

voidstate
  • 7,937
  • 4
  • 40
  • 52

3 Answers3

2

In the end, xyu's link got me the answer.

First, I mixed in a new function to the tree on instantiation:

var myTree = new Tree( 
{
    model: treeModel, 
    autoExpand: true,
    showRoot: false,
    title: 'My Items',
    openOnClick: true,
    getDomNodeById: function( id ) // new function to find DOM node
    {
        return this._itemNodesMap[ id ][0];
    }
} );

Then I could call it like this:

var treeNode = myTree.getDomNodeById( dataId );
voidstate
  • 7,937
  • 4
  • 40
  • 52
0

According to the API dijit/Tree has a domNode property. It should point to DOM node, where the tree is located.

undefined
  • 2,051
  • 3
  • 26
  • 47
  • But I can find the tree. It's the specific leaf DOM node which represents the id that I want. – voidstate Nov 19 '12 at 15:06
  • Take a look at [this question](http://stackoverflow.com/questions/2005743/getting-a-dojo-node-when-i-have-the-store-item-id). – undefined Nov 19 '12 at 15:13
-1
//code<1.7
dojo.connect('id of tree','onClick',function(evt)
{
  console.log(evt.id[0]);
  //onclick event tree return id of its node in array
});

//code>1.7
require(['dojo/on'],function()
{
  on('id of tree','click',function(evt)
  {
    console.log(evt.id[0]);
    //onclick event tree return id of its node in array
  });
});
Mithlesh Kumar
  • 748
  • 7
  • 16