Reputation: 4236
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.
Upvotes: 1
Views: 1470
Reputation: 393
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).
Upvotes: 1