主干事件未绑定

发布于 2025-01-08 17:18:52 字数 836 浏览 5 评论 0原文

谁能告诉我为什么下面的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蓝天 2025-01-15 17:18:52

在渲染中尝试 @delegateEvents()

Try @delegateEvents() in render

夏日浅笑〃 2025-01-15 17:18:52

弄清楚了,这和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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文