[英]calling a method from jquery callback with coffeescript
在coffescript中,我想從jquery回調中調用一個類方法,如何訪問類的范圍? this.loadImage(currentIndex)不起作用
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 "+@index)
您需要使用=>
運算符進行回調。 您可能會發現此信息有用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.