2

我在获取 ember 视图以响应来自视频标签的“结束”视图时遇到问题 - 我什至在应用程序中设置了一个自定义并在视图上创建了一个结束的方法,但没有骰子。我设法通过视图的 didInsertElement 中的 $() 得到一些东西,但是视图的标准“on”方法什么也没做——就像事件正在元素上发生,但没有进入视图。但是通过 $ 设置意味着“this”不是绑定到视图而是绑定到元素,这对我没有太大帮助

我的观点:

CommercialView: Em.View.extend
            tagName: 'video'
            templateName: "commercial"
            attributeBindings: ['autoplay', 'width', 'height']
            width: 320
            height: 240
            autoplay: true
            ended: (event) ->
                debugger
            didInsertElement: () ->
                #this.on('ended', this.ended)​ #doesn't work
                this.$().on('ended', this.ended) #shifts this to the element 

我的应用程序:

App = Em.Application.create
    customEvents: {
        'ended':'ended'
    }
4

1 回答 1

4

这是 jQuery 的限制,Ember 将其用于事件。它只是不能委托视频或音频事件:http: //jsfiddle.net/XzVXx/

不幸的是,它也缺乏context为像 for 那样的事件提供参数的能力$.ajax(),所以当然你不能指定什么this意思。

您将得到的最接近的是:

didInsertElement: function(){
  this.$().on('ended', $.proxy( this.ended, this )) ;
}
于 2012-09-26T11:52:59.693 回答