I've implemented a Menu widget connected to my 'vehicles' DnD Tree widget.
The Menu enables/disables different MenuItems depending on which type of node
you right-clicked on. On a branch node (one with underlying children) only the
'Add child' MenuItem is enabled. Selecting this MenuItem opens a Dialog widget
so you can enter the name of a new vehicle then click the 'Insert' Button
widget, which calls the insert_vehicle_tree_node() function.
So far so good. But I'm at a loss as to how to proceed. Presumably I need to
create a new TreeNode widget then insert it into the vehicle Tree's store in
the appropriate place. But how? Within insert_vehicle_tree_node how can I
determine which TreeNode 'Add child' is currently positioned on, create a new
TreeNode then insert it in the correct place?
You can try this yourself at
http://edawizardry.com/testtree_8.jsp
TIA,
Still-learning Stuart
_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
Dojo-i...@mail.dojotoolkit.org
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
dojo.connect(menu, "_openMyself", this, function(e){
// get a hold of, and log out, the tree node that was the source of this open event
var tn = dijit.getEnclosingWidget(e.target);
console.debug(tn);
I added these new lines
line 114 dynamic_A_file_tree.attr("selectedItem", tnitem);
line 321 mytree.attr("selectedItem")
into
http://edawizardry.com/testtree_8b.jsp
and it works like a charm. Yippee!!!! One last question - is .selectedItem
defined in Dojo or is it a custom attribute I just created?
THANK YOU SO MUCH FOR HELPING SEE ME THROUGH THIS!!!
My project can now process.
Onward! (to the next snag...)
Thanks again,
Still-learning Stuart
OK, I've found the next snag. Line 323 of
http://edawizardry.com/testtree_8b.jsp
is
mytree.model.newItem( newItemParams, currParentItem);
which does insert the new child node under the parent. But it inserts the new
node as the *last* child under the parent and I need the new node to be
inserted in a specific position to maintain the sorted order of the children.
How can I achieve this?
Is there some function of the Dojo model or store like .insertBefore or
.insertAfter where you specifiy exacly where you want the new item to be placed?
Or must I use model.newItem asis and create a function to put the parents'
children in correct order ie.
mytree.model.newItem( newItemParams, currParentItem);
myChildrenSortingFunction( currParentItem);
Any ideas?
Ah, you want a third argument to newItem() representing the insertIndex:
newItem: function(/* dojo.dnd.Item */ args, /*Item*/ parent, /*int?*/ insertIndex)
It doesn't show up on http://api.dojotoolkit.org/jsdoc/trunk/dijit.tree.TreeStoreModel for some reason, but it's there.
Undocumented features, hai! Alright I will give this a try.
Many thanks (again)!
Hm, no joy. I attempt to force the insertion at index 2 on line 326 of
http://edawizardry.com/testtree_8c.jsp
But the new node always appears as the last child, obviously being appended.
Is there some deeper knowledge I'm lacking in applying the index? Meaning, if
I want to force the new child to be added between the 2nd and 3rd existing
child should I use "2"? Or is the index absolute, calculated from the root?
Ah, alright, should I be installing the Tree.js from trunk locally then?
Thx,