我有一个dijit /树,工作正常。但是,我不知道如何从id(商店中的id,而不是DOM id)中获取特定行的DOM节点。如何通过Id获取dijit/Tree节点?
喜欢的东西:
myTreeModel.getDomNodeById(id);
我使用的dijit /树的dijit /树/ ObjectStoreModel和道场/存储/ MemoryStore的。
一切似乎都是为了获取商店数据,但我想要改变一个DOM节点上的类,以响应我的应用程序中其他地方的事件。
我有一个dijit /树,工作正常。但是,我不知道如何从id(商店中的id,而不是DOM id)中获取特定行的DOM节点。如何通过Id获取dijit/Tree节点?
喜欢的东西:
myTreeModel.getDomNodeById(id);
我使用的dijit /树的dijit /树/ ObjectStoreModel和道场/存储/ MemoryStore的。
一切似乎都是为了获取商店数据,但我想要改变一个DOM节点上的类,以响应我的应用程序中其他地方的事件。
根据APIdijit/Tree
有一个domNode
财产。它应该指向树所在的DOM节点。
//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
});
});
最后,xyu的链接给了我答案。
首先,我在一个新的功能混合到树实例:
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];
}
});
然后,我可以这样称呼它:
var treeNode = myTree.getDomNodeById(dataId);
但我可以找到树。它是代表我想要的id的特定叶子DOM节点。 – voidstate
看看[这个问题](http://stackoverflow.com/questions/2005743/getting-a-dojo-node-when-i-have-the-store-item-id)。 – undefined
这样做。谢谢! – voidstate