+ Start a Discussion
djordandjordan 

Dojo help! Trouble getting 2 clicks on treeNodes

Dear community,

I’m using the Ajaxtools scontrol developer tool which is very handy, but am having trouble with some dojo (0.4.x) code which constructs a tree of groups. I’m having some trouble getting a handle to click events on TreeNodes.

What I want is simple: If the user clicks on a node, then call a function called “busiessLogic”. If they click on the same node, then call the same function again.

Here’s the code.
// Make the tree & root node
tree = dojo.widget.createWidget("Tree", {selector: "tSelector" });
document.getElementById("tree").appendChild(tree.domNode);
rootNode = dojo.widget.createWidget("TreeNode",{title: "Groups", widgetId: “rootOfAllNodes”});

// Now add the 1st level nodes
while(yada-yada)
...
   groupNode = dojo.widget.createWidget("TreeNode", {title: gName, widgetId: gId});
   rootNode.addChild(groupNode);
..
 
To get a handle on the click event, I have tried 2 approaches but have issues with both
1) Subscribe to the nodeClicked event:
dojo.addOnLoad(function()
{
    dojo.event.topic.subscribe("nodeClicked", function(message){ busiessLogic(message.node.widgetId); });
});

This works, in that if the user clicks on the node, then busnessLogic() is called
BUT IF THE USER’S NEXT CLICKS IS ON THE SAME NODE, THEN NO EVENT IS GENERATED.

i.e. If they click on Node A then node B and then Node A again, all is well. If they click on Node A, then Node A again, the 2nd event is lost.

2) Connect to the event. I tried variations on this but can’t get any of them to work at all
dojo.event.connect(groupNode, "onclick", "nodeClickCallback");
dojo.event.connect(groupNode, "onClick", "nodeClickCallback");
dojo.event.connect(groupNode, "onClick", nodeClickCallback);
dojo.event.connect(groupNode, "onClick", nodeClickCallback(myWId));
...
function nodeClickCallback(nodeId) {return function(nodeId) { busiessLogic(nodeId); };}
 
 
Any help would be greatly appreciated.

David