【发布时间】:2012-01-23 01:09:45
【问题描述】:
我上课了:
class @GameMap
options : {
'width' : 100,
'height' : 100,
'tileWidth' : 45,
'tileHeight' : 20,
'scale' : 5,
'moveDistance' : 100, #Distance to move with the map controlers
'showErrorMessages' : true,
'zindexDecorElementBase' : 99999,
'zindexGroudElementBase' : 88888
}
lang : {
'errContainerMissing' : "L'élement pour créer la carte n'existe pas"
}
constructor: (@element) ->
this.run()
run: ->
this.loadDatas()
loadDatas: (top,left) ->
$.ajax(
url: "/map/getnewcoord",
data: {
map_width : this.options.width,
map_height : this.options.height,
tile_height : this.options.tileHeight,
tile_width : this.options.tileWidth,
window_large : $('.map-windows').width(),
window_height: $('.map-windows').height(),
top : top ,
left : left
},
success: (data) ->
$.each(data,(index,item) ->
this.createTile(item.posX,item.posY);
)
)
createTile: (m,n) ->
#We are in the tile reference
yDelta = Math.round((options.width ) * options.tileHeight );
console.log('pass')
$ ->
gamemap = new GameMap("#map .block-map")
但我得到了错误
this.createTile 不是函数
这是因为“this”不是我班级的“this”,而是我的 json 调用返回的项目之一。
如何在 ajax 成功回调函数中保留我的类的“this”?
【问题讨论】:
标签: javascript jquery ajax coffeescript