Search code examples
javascriptdojodijit.tree

I want Dojo Tree Context Menu NOT fired for some nodes?


I have a Dojo Tree and a related Dojo Menu. I want this context menu popup for certain types of nodes and not for the others. The Tree is not static and items are added at runtime.

Is there an Event (onBefore) of Menu that is fired before popping up and behaves according to your return value ?

Is there a Property of Menu that keeps it silent for some time ? Like I have this Tree.onMouseDown handler and if the item right-clicked should not show a context menu, then I untrigger the Menu or it ignores the RightClick so that it does not popup ?


Solution

  • dijit/Menu has a property called "targetNodeIds". It's an array of target node IDs that you can populate at startup. Subsequent nodes can be attached through dijit/Menu's "bindDomNode(node)" method.

    There is also a "selector" property for dijit/Menu, that allows you to specify a class on the nodes you want to use as a target. Just create your tree nodes with a particular class and set this class name to be the "selector" property.

    See http://livedocs.dojotoolkit.org/dijit/Menu#attaching-to-multiple-nodes