0

**I'm building dojo tree using the following code: enter image description here

The tree is displayed as expected. The problem that I have is that the onClick event is only fired on leaf nodes. When I click on the root level node(I have several root level) it is just open showing child nodes.

How can I add "extra" onClick functionality to the root nodes?

BigWonder
  • 225
  • 1
  • 4
  • 18

1 Answers1

2

You've got openOnClick set to true for your tree. I think the API docs answer this as well as I possibly could.

http://dojotoolkit.org/api/dijit/Tree/openOnClick

That said, it looks like you'd be able to connect to _onClick instead and do whatever you want (that's the method responsible for calling onClick only when openOnClick is false, anyway). Or, if you wanted to feel a little less guilty about accessing private members, dojo.declare yourself a subclass of dijit.Tree, extending _onClick to also fire another function you define as public.

Ken Franqueiro
  • 10,559
  • 2
  • 23
  • 40
  • I need to have actually both events enabled openOnClick and onClick. Can you please instruct how to set those variables. I have really minor experience with DOJO. Thank you in advance. – BigWonder Jan 26 '11 at 03:47
  • I already told you; in the simplest case, connect to _onClick. In your current example, you'd change `"dojo/method"` to `"dojo/connect"` (so that you'll be connecting to method invocations, not clobbering the method), then change `event="onClick"` to `event="_onClick"`. – Ken Franqueiro Jan 26 '11 at 05:13
  • I just changed openOnClick to "false" and it is working. Thank you – BigWonder Jan 26 '11 at 14:52