简体   繁体   中英

How to Get a dijit/Tree Node by Id?

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.

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 );

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

//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
  });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM