【发布时间】:2013-11-30 15:01:00
【问题描述】:
我正在使用最新的 ember js 并且有以下视图:
App.PeriodSelectorView = Em.View.extend
classNames: "period-selector"
templateName: "period_selector"
didInsertElement: ->
@$().draggable()
@setupTimeSlider()
setupTimeSlider: ->
@$(".time-slider").slider
value: 20
min: 20 # 0500 in the morning
max: 83 # 2045 in the evening
step: 1
slide: @updateTimeValue
updateTimeValue: (event, ui) ->
@set("time", ui.value)
现在,当滑块更改时,回调会触发,但 this 设置为 window 而不是视图实例。所以调用this.set 失败。
我已经尝试使用 coffeescript 的胖箭头 (=>) 运算符将方法 updateTimeValue 绑定到实例,但它不起作用。
如何让this 指向视图实例而不是window?
【问题讨论】:
-
您能否详细说明您如何尝试使用
=>?这个答案似乎暗示它应该工作:stackoverflow.com/questions/8965855/… -
我只是使用 => insteaf of -> 作为 updateTimeValue。但是我只是从编译的代码中看到,实际上这并没有做任何事情。原因似乎是我不使用“class App.PeriodSelectorView extends Em.View”。但是我不能使用这种形式,因为这样就没有任何效果,只会抛出一堆异常......我必须深入研究一下。
标签: jquery-ui ember.js coffeescript