简体   繁体   English

解析dijit.tree中的节点

[英]Parse nodes in a dijit.tree

I'm struggling with a dijit.Tree and I can't find what I need in the dojo documentation... 我在与dijit.Tree斗争,我在dojo文档中找不到我需要的东西...

I want to change the style of a few elements in my tree, according to some conditions. 我想根据某些条件更改树中一些元素的样式。

I am able to identify the elements through a combination of for loops and if evaluations : 我可以通过for循环和if评估的组合来识别元素:

itemList = this.tree.model.store._arrayOfAllItems;
for (var index in itemList) {
    item = itemList[index];
    if (item.<property> == ...) {
       ...
       //This is where I want to change the style
       ...
    }
    ...
}

But then, I fail to get the node id to call dojo.addClass(nodeId, newClass). 但是然后,我无法获取节点ID来调用dojo.addClass(nodeId,newClass)。

Am I parsing through the proper list, with the model.store._arrayOfAllItems? 我是否使用model.store._arrayOfAllItems解析正确的列表? Is there a way to parse through the node list instead, and still access the data properties? 有没有一种方法可以解析节点列表,并仍然访问数据属性?

Thank you very much for your help! 非常感谢您的帮助!


Edit on 2015-11-23 于2015-11-23编辑

With Richard's comments, I was able to obtain the result I was looking for. 有了Richard的评论,我能够获得想要的结果。 I have added a handler that connects the tree's onOpen event to a method that gets the open node map (from tree._itemNodesMap) and then fetch through the store. 我添加了一个处理程序,该处理程序将树的onOpen事件连接到获取开放节点映射(从tree._itemNodesMap)然后通过存储获取的方法。 For every item in the store, it adjust the css if the id of the item being validated has an associated node in the open node map. 对于商店中的每个商品,如果要验证的商品的ID在开放节点图中具有关联的节点,它将调整CSS。 It then looks recursively for children. 然后递归地为儿童查找。

Thanks Richard for your help! 感谢理查德的帮助!

If you have the id of the node inside the tree, you can use the getNodesByItem function that tree has. 如果您在树中拥有该节点的ID,则可以使用该树具有的getNodesByItem函数。

Although if your tree is dynamic and the contents can change, I would suggest writing a function that not only adds to your store but also adds to a class for the node formed in the tree. 尽管如果树是动态的并且内容可以更改,我建议编写一个函数,该函数不仅可以添加到您的商店中,还可以添加到树中形成的节点的类中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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