Why audio events are not firing with BackboneJS but others are?

后端 未结 1 1395
甜味超标
甜味超标 2021-01-01 07:42

I don\'t understand why the click events are firing ok but not the timeupdate one.

No event is firing from , I tr

1条回答
  •  温柔的废话
    2021-01-01 07:59

    Backbone internally converts the events object and binds the events by delegation. This means that

    events: {
            'timeupdate .audio': 'onTimeUpdate',
            'click .btn_play': 'onClickPlay'
    }
    

    ends as

    this.$el.delegate('.audio','timeupdate', this.onTimeUpdate);
    this.$el.delegate('.btn_play','click', this.onClickPlay);
    

    But there's a catch:

    Uses event delegation for efficiency. [...] This only works for delegate-able events: not focus, blur, and not change, submit, and reset in Internet Explorer.

    And it would appear that audio events are not delegate-able.

    However, setting directly the callbacks does work, for example you could replace your initialize function by

    initialize: function() {
        this.$el.html(this.template(this.model.toJSON()));
        _.bindAll(this,'onTimeUpdate');
        this.$('.audio').on('timeupdate', this.onTimeUpdate);
    }
    

    0 讨论(0)
提交回复
热议问题