如何在dojo.connect中传递元素

时间:2012-10-05 23:23:24

标签: javascript dojo event-handling thumbnails mouseover

我在dojo中创建一个小部件,可以放大鼠标上的缩略图。

小部件将鼠标悬停事件与构造函数中的所有缩略图绑定在一起,如下所示:

dojo.connect(imgTag, "mouseover", this, "_showImgPreview");

在_showImgPreview()中,我需要发生鼠标悬停事件的图像。通过上面的操作我只得到了事件,而不是图像。

如何获取_showImgPreview()中发生事件的缩略图?

我知道我可以这样做,但我很想知道如何使用上述方法做到这一点。

var self = this;
dojo.connect(imgTag, "mouseover", function(e){
   self._showImgPreview(e, this);
});

提前谢谢!

1 个答案:

答案 0 :(得分:2)

e.target将是imgTag。

如果您在扩展Widget的类中,则可以使用

this.connect(imgTag, "mouseover", "_showImgPreview");

如果不是,您可以使用

dojo.connect(imgTag, "mouseover", dojo.hitch(this, this._showImgPreview));

注意:dojo/connect已被弃用,转而使用dojo/on