這裏是我的控制器js.coffee文件中的咖啡腳本代碼。我只是試圖打開一個簡單的地圖集中在一個特定的位置等我的地圖工作,並且moveend_event
回調被觸發,因爲如果我取消註釋alert("hello")
調用它的工作正常。我在這裏有OpenLayers/jQuery衝突嗎?
$(document).ready ->
map = undefined
options =
projection: new OpenLayers.Projection('EPSG:900913')
displayProjection: new OpenLayers.Projection("EPSG:4326")
center: new OpenLayers.LonLat(-115.540123, 54.073189)
controls: [new OpenLayers.Control.Navigation(), new OpenLayers.Control.PanZoomBar(), new OpenLayers.Control.LayerSwitcher()]
eventListeners:
'moveend': moveend_event
map = new OpenLayers.Map("map_element", options)
osm = new OpenLayers.Layer.OSM('OpenStreetMap Layer')
map.addLayer osm
map_center = new OpenLayers.LonLat(-115.540123, 54.073189).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject())
map.setCenter(map_center, 11)
moveend_event = ->
#alert "Hello!"
#$(".map_location").innerHTML "Hello!"
我很接近,但我不能認爲我可能有Openlayers/jQuery衝突。如果我嘗試設置我的map_location DIV與$(".map_location").innerHTML "Hello!"
頁面創建者和錯誤控制檯顯示:
TypeError: 'undefined' is not a function (evaluating '$(".map_location").innerHTML("Hello!")')
我已經打開層之前的jQuery裝載有沒有什麼幫助。我做了一些谷歌搜索,它可能是jQuery noConflict模式(http://api.jquery.com/jQuery.noConflict/),但我是一個javascript新手,我不知道足夠的認識到這個問題或如何解決它。我相信這是一個簡單的解決方案,但我目前沒有線索。
我正式成爲白癡jQuery的對應 - 即固定它。 –