Backbone events on model firing on collection (Double firing)

只愿长相守 提交于 2019-12-04 06:28:17

From the fine manual:

Any event that is triggered on a model in a collection will also be triggered on the collection directly, for convenience.

So yes, the collection listens to events on all of its models and forwards them.

For example, given a simple set up like this:

class M extends Backbone.Model

class C extends Backbone.Collection
    model: M

c = new C
c.on('change', (model, opts) -> console.log('Change on collection'))

Doing c.first().set(...) will trigger the event handler.

Demo: http://jsfiddle.net/ambiguous/wwjnK/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!