Dojo 树父节点

发布于 2024-12-11 06:31:44 字数 586 浏览 0 评论 0原文

我想知道是否有人有办法获取道场树中项目的父节点?我已经尝试过,但似乎不起作用。

我尝试了几种不同的方法。

首先我尝试了这个:

this.tree.get("path")[this.tree.get("path").length - 2];

接下来我尝试了我在这个网站上找到的内容: http://dojo-toolkit.33424.n3.nabble.com/how-do-I-get-the-parent-node-of-a-dijit-Tree-node-td1788430.html< /a>\

似乎都不起作用。我不知道为什么这是一个如此复杂的事情,因为这可能是一个非常常见的操作。如果你能帮我解决这个问题那就太好了。

谢谢

编辑:我想更让我失望的是我首先尝试的方法(提供的代码示例)有时会起作用。所以这真的让我很困惑。

I was wondering if anyone had a way to get the parent node of an item in a dojo tree? I have tried but it doesn't seem to work.

I have tried a few different ways.

First I tried this:

this.tree.get("path")[this.tree.get("path").length - 2];

Next I tried what I found on this site: http://dojo-toolkit.33424.n3.nabble.com/how-do-I-get-the-parent-node-of-a-dijit-Tree-node-td1788430.html\

Neither one seems to work. I don't know why this is such a complicated thing when it is presumably a pretty common operation. If you could help me with this that would be awesome.

Thanks

EDIT: I guess what's throwing me off even more is that the method I tried first (the code sample provided) sometimes work. So this is really confusing me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

原来是傀儡 2024-12-18 06:31:44

使用 Dojo v1.7,我使用了:

// Very similar to your code (maybe even functionally equivalent)
tree.path[tree.path.length - 2]; 

该代码已被重构,但我很确定它有效。需要注意的一些事情是 1) 我认为这仅在您正在查找的父项目需要是选定项目 (tree.selectedItems[0]) 时才有效,并且 2) 如果以下情况,此行可能不起作用您选择的项目是树的根(如果根被隐藏,则为顶级项目)。

Using Dojo v1.7, I have used:

// Very similar to your code (maybe even functionally equivalent)
tree.path[tree.path.length - 2]; 

That code has since been refactored away, but I'm pretty sure it worked. Some of the things to be aware of with this is 1) I think this only works if the item whose parent you are looking for needs to be a selected item (tree.selectedItems[0]) and 2) this line might not work if your selected item is the tree's root (or the top level item if the root is hidden).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文