1
在coffescript中,我想從jquery回調中調用一個類方法,我如何訪問類的範圍? this.loadImage(CURRENTINDEX)does not工作從cquery腳本中調用jquery回調方法
class ImageCarousel
currentIndex = 0
jsonPath = "json/images.json"
images = null
constructor:() ->
this.loadJson()
loadJson:() ->
$.ajax jsonPath,
success : (data, status, xhr) ->
console.log("yea "+data)
this.images = data.images
this.loadImage(currentIndex)
error : (xhr, status, err) ->
console.log("nah "+err)
complete : (xhr, status) ->
console.log("comp")
loadImage:(@index) ->
console.log("load image "[email protected])
可能的重複[如何留在這個上下文在ajax調用(jquery + coffescript)](http://stackoverflow.com/questions/8552270/how-to-stay-in-the-this-context -during-AN-AJAX的呼叫jQuery的coffescript) – Nix