Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/415.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaScript作用域基础:侦听自定义事件?_Javascript_Google Maps_Backbone.js - Fatal编程技术网

JavaScript作用域基础:侦听自定义事件?

JavaScript作用域基础:侦听自定义事件?,javascript,google-maps,backbone.js,Javascript,Google Maps,Backbone.js,关于JavaScript作用域的问题。我有三个文件(我使用的是主干网,但我不确定这是否相关)。第一个文件定义了一个谷歌地图自定义信息窗口。第二个文件定义了一个Google Maps标记,并将infowindow应用于它。最后,第三个文件将标记和其他页面元素添加到地图中 我希望第三个文件能够监听infowindow上的mouseover事件,并在其他页面元素上调用方法。但是,我的JavaScript不够好,无法了解如何: // InfoWindow.js defines the info wind

关于JavaScript作用域的问题。我有三个文件(我使用的是主干网,但我不确定这是否相关)。第一个文件定义了一个谷歌地图自定义信息窗口。第二个文件定义了一个Google Maps标记,并将infowindow应用于它。最后,第三个文件将标记和其他页面元素添加到地图中

我希望第三个文件能够监听infowindow上的mouseover事件,并在其他页面元素上调用方法。但是,我的JavaScript不够好,无法了解如何:

// InfoWindow.js defines the info window & adds a mouseover event
AI.InfoWindow.prototype = new google.maps.OverlayView;
AI.InfoWindow.prototype.onAdd = function() {
  this.listeners = [
    google.maps.event.addDomListener(this.$content.get(0), "mouseover", function (e) {
       clearTimeout( window.hidePopupTimeoutId );
    }) ...
  ];
};

// Marker.js defines the map marker and adds the infowindow 
AI.Marker = function() {
  google.maps.Marker.prototype.constructor.apply(this, arguments);
  this.infoWindow = new AI.InfoWindow();
}

// Home.js creates the markers for the map
var myOtherHomePageElement = new AI.OtherHomePageElement();
var marker = new AI.Marker({
   data: entity 
});
// how to listen to infowindow events here?

所以我的问题是:infowindow上的鼠标悬停工作正常,但我希望能够在有鼠标悬停时调用
myOtherPageElement.start()
。如何从Home.js文件中执行此操作?

您可以使用
Backbone.trigger
Backbone.on
在鼠标悬停时通知Home.js中的对象

// InfoWindow.js defines the info window & adds a mouseover event
AI.InfoWindow.prototype = new google.maps.OverlayView;
AI.InfoWindow.prototype.onAdd = function() {
  this.listeners = [
    google.maps.event.addDomListener(this.$content.get(0), "mouseover", function (e) {
       clearTimeout( window.hidePopupTimeoutId );
       Backbone.trigger('infowindow:mouseover', e);
    }) ...
  ];
};

// Marker.js defines the map marker and adds the infowindow 
AI.Marker = function() {
  google.maps.Marker.prototype.constructor.apply(this, arguments);
  this.infoWindow = new AI.InfoWindow();
}

// Home.js creates the markers for the map
var myOtherHomePageElement = new AI.OtherHomePageElement();
var marker = new AI.Marker({
   data: entity 
});
Backbone.on('infowindow:mouseover', myOtherHomePageElement.start, myOtherHomePageElement);