Failure to trap dijit.Tree "onclick"

1.3k Views Asked by At

I've read several examples of handling onClick for dijit.Tree.. in particular this one seems to tell me all I need: dojo how to override dijit class method

However, for some reason my handler gets called when my page first loads, and never when I click on a tree node?

Here's the code:

<div dojoType="dijit.layout.ContentPane" title="Published Blueprints" minSize="20" style="width: 300px;" id="leftAccordion" region="leading" splitter="true">
   <div id="blueprintTree" dojoType="dijit.Tree" store="" query="" label="Blueprints" openOnClick="false">
   </div>
</div>

...and I then do this...

dojo.ready(function() {
   var tree = dijit.byId("blueprintTree");
   tree.connect(tree, "onClick", function(item) {
       // my code here...
   });
});

... the "my code here" part gets invoked when I start (in debug) my jsp, but never when i lock around on nodes...

Obviously I'm missing something simple?

Regards Brian

1

There are 1 best solutions below

0
On

Is it required to put the connect inside the dojo.ready()? Maybe that is why it is called on startup?

Looking at the dijit.Tree source, I saw that the onClick had two args This is what I used in my case to successfully capture onClicks:

In the Tree constructor add openOnClick: false:

var tree = new dijit.Tree( {
        model: myModel,
        openOnClick: false,
                    etc...

Then in the same function where I create the tree using the programmatic approach

dojo.connect( tree,"onClick", function(/*dojo.data*/ item, /*TreeNode*/ nodeWidget){
    //my code
});