开发者

How do you access the event that is used for dojo.event.connect in the function that is being called?

开发者 https://www.devze.com 2023-03-23 21:03 出处:网络
First off, I am using a version of older version of dojo, so dojo.event.connect is the proper syntax.My question is this: How do I access the event in the function that I call when the event is fired.

First off, I am using a version of older version of dojo, so dojo.event.connect is the proper syntax. My question is this: How do I access the event in the function that I call when the event is fired.

Basically, Ii am dynamically creating a button and then connecting an event on "onClick"

var _btn = dojo.widget.createWidget(widget parameter开发者_JAVA百科s);
dojo.event.connect(_btn,"onClick","myFunction");

In myFunction, I need to be able to access the attributes of _btn. I have tried passing _btn as the context of dojo.event.connect but this doesn't work. It also wont pass _btn as a parameter for myFunction when I try that. Is it possible to either A) somehow pass _btn as a parameter into myFunction or B) Access the event that is fired in myFunction when _btn is clicked.


I don't know if there is a more convenient way to solve your problem, but in the worst case, you could just use a closure as a surefire way to pass the parameter:

change myfunction from

myfunction(arg1, arg2){

into

myfunction(btn, arg1, arg2){
     //using btn here

and use dojo.partial (or dojo.hitch) to create a function that always reveives a certain button as a parameter (and then pass it to the connect):

dojo.event.connect(_btn, 'onClick', dojo.partial(myFunction, _btn));
0

精彩评论

暂无评论...
验证码 换一张
取 消