首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Backbone事件未触发-谷歌地图InfoBubble

Backbone事件未触发-谷歌地图InfoBubble
EN

Stack Overflow用户
提问于 2012-10-10 21:33:51
回答 1查看 258关注 0票数 1

我正在尝试触发一个事件,点击谷歌地图内的谷歌信息气泡。

代码语言:javascript
复制
class MapSite.Views.Maps extends Backbone.View

  events:
    'click [name=testdrive]' : 'initControls'

  initialize: ->
    @render()

  render: ->
    @el = $("#map")  
    $this = $(this.el)
    @loadMap()

  initControls: ->
    alert "hello"

  loadMap: ->
    osmMapType = new google.maps.ImageMapType(
      getTileUrl: (coord, zoom) ->
        "http://tile.openstreetmap.org/#{zoom}/#{coord.x}/#{coord.y}.png"
      tileSize: new google.maps.Size(256, 256)
      isPng: true
      alt: "OpenStreetMap layer"
      name: "OSM"
      maxZoom: 19
    )

    cloudMadeMapType = new google.maps.ImageMapType(
      getTileUrl: (coord, zoom) ->
        "http://b.tile.cloudmade.com/****/54912/256/#{zoom}/#{coord.x}/#{coord.y}.png"
      tileSize: new google.maps.Size(256, 256)
      isPng: true
      alt: "CloudMade layer"
      name: "CMade"
      maxZoom: 13
    )

    lat = 51.503
    lng = -0.113
    latlng = new google.maps.LatLng(lat, lng)
    options =
      zoom: 10
      center: latlng
      mapTypeId: 'OSM'
    @gMap = new google.maps.Map(document.getElementById("map"), options)
    @gMap.mapTypes.set('OSM', osmMapType)
    @gMap.mapTypes.set('CloudMade', cloudMadeMapType)
    @gMap.setMapTypeId('CloudMade')


    @initShape()
    @initLabel()



initLabel: ->
    console.log("This is where the label should appear")
    initLabel = new InfoBubble(
      position: new google.maps.LatLng(51.44115356738888, 0.14849636779354114)
      maxWidth: 240
      maxHeight: 210
      shadowStyle: 1
      padding: 0
      content: '<div class="tooltip_header"><h4>Hello</h4></div><div class="tooltip_content"><p>Nunc nec, egestas vel augue rhoncus massa cras, tincidunt a nisi nisi est lundium non sed? Eros pulvinar</p></div> <div id="tooltip_buttons" class="tooltip_buttons"><button class="btn btn-success" name="testdrive">Test Drive</button> <button class="btn btn-warning">Read More</button></div>',
      tabPadding: 12
      backgroundColor: 'black'
      borderRadius: 0
      arrowSize: 10
      borderWidth: 0
      borderColor: '#AB2424'
      disableAutoPan: true
      hideCloseButton: false
      arrowPosition: 0.5
      backgroundClassName: 'phoney'
      tabClassName: 'tabClass'
      activeTabClassName: 'activeTabClass'
      arrowStyle: 2
      )

    initLabel.open(@gMap)

结束

地图加载得很好,信息气泡就在那里。然后,我尝试并将一个事件链接到正在被单击的事件,但它没有触发。我已经将el设置为"# map“,并且该信息气泡的div位于map div中。

基本上,我需要结束的是一个事件,当点击信息气泡中的按钮时就会触发该事件。我想这可能是因为Backbone看不到信息泡沫,因为它在加载之后会加载,所以不能自己附加吗?

EN

回答 1

Stack Overflow用户

发布于 2012-10-10 21:44:24

默认情况下,主干视图中的事件使用事件委派绑定到根el。因为你在事件“丢失”之后切换了你的el

您可以尝试使用delegateEvents方法reDelegateging您的事件。

顺便说一句,我看到你正在缓存$(this.el),这不再是必要的,因为你现在可以使用$el来代替(我认为从backbone.js 0.9.2开始)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12820632

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档