主干事件未绑定
谁能告诉我为什么下面的 PlayerView 代码中的“点击”事件没有被正确绑定/触发?我觉得我错过了一些非常明显的东西,但在尝试了许多不同的解决方案后,我感到不知所措。
这就是它在路由器中实例化的方式:
App.playerView = new App.Views.PlayerView
el: $("#player")
collection: App.tracks
这是实际的视图代码(在 Coffeescript 中,带有 jPlayer 插件代码,以防相关):
App.Views.PlayerView = Backbone.View.extend
events:
"click .jp-next": "next"
"click .jp-back": "back"
initialize: ->
_.bindAll @, 'render'
@template = _.template $('#player-template').html()
@collection.bind 'reset', @render
@render()
play: (track) ->
...
next: ->
...
back: ->
...
render: ->
$(@el).html @template {}
@player = $("#jplayer").jPlayer
"swfPath": "/"
ready: =>
@next()
ended: =>
@next()
@
Can anyone tell me why the "click" events in the PlayerView code below are not being correctly bound/fired? I feel like I'm missing something very obvious, but after hours of trying many different solutions, I am at a loss.
This is how it's being instantiated in the router:
App.playerView = new App.Views.PlayerView
el: $("#player")
collection: App.tracks
and here is the actual view code (in Coffeescript with jPlayer plugin code in case it's related):
App.Views.PlayerView = Backbone.View.extend
events:
"click .jp-next": "next"
"click .jp-back": "back"
initialize: ->
_.bindAll @, 'render'
@template = _.template $('#player-template').html()
@collection.bind 'reset', @render
@render()
play: (track) ->
...
next: ->
...
back: ->
...
render: ->
$(@el).html @template {}
@player = $("#jplayer").jPlayer
"swfPath": "/"
ready: =>
@next()
ended: =>
@next()
@
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在渲染中尝试 @delegateEvents()
Try @delegateEvents() in render
弄清楚了,这和jPlayer有关。 jPlayer 在事后以某种方式覆盖了事件,因此我只是删除了脚本中的该功能以使其正常工作。虽然很痛苦,但还是感谢所有帮助过的人!
Figured this out, and it was jPlayer related. jPlayer was somehow overriding the events after the fact, so I just removed that functionality in their script to get it to work. What a pain, but thanks for all who helped!