dojo attachevent. I want to trigger a handler in an entirely different component
In dojo, You can have something to this effect.
<div id='outer' dojoType=OuterWidget>
<div dojoType=InnerWidget dojoAttachEvent='onmousein:_privateHandler, on...'>
</div>
</div>
But my scenario, is that I want to lay out a declarative description of my application widget layout like that, but have the mousein event of the inner component trigger a handler on the outer component.
I might have to resort to onmousein='dijit.byId("outer").outerHandler()' But it seems like dojo should have built a way to do this.
Also, on a related not (if someone knows how to do extention points) I want to be able to say that an extension point of the inner element should merely refer to some handler of the outer. (The only distinction now being that I'd like to point an extension point to the outer handler as opposed to just a native DOM event.)
I would really appreciate any help you guys can offer开发者_运维知识库 on this one :)
Dijit does have a getParent method for widgets which implement a Container-Contained relationship, but it basically does a walk up the DOM looking for a node with the markings of a Dijit Widget (a widgetid attribute, IIRC. Once you establish this relationship, you should be able to simply do something like a dojo.connect to bind one event to another. You'd best avoid ids, since they're instance specific. It's a bit like using a global variable.
I found that this worked: Asume the html represents a template for the parent class, which always includes a child:
<div > // no id or dojoType specified in the parent's template:
<div dojoType='innerWidget' idOfWidgetThatShouldHandleMouseIn=${id}>
</div>
</div>
The ${id} will be mapped to the exact id of whatever *instance* is created of the parent component.
精彩评论