I have a view myView
and a collection myCollection
. When I add
a model to myCollection
, the add
event is trigger
After ver. 0.9.9 (added Dec. 13, 2012) it is recommended to use listenTO.
In line with this:
var MyView = Backbone.View.extend({
initialize: function() {
this.listenTo(this.collection, 'add', this.onModelAdd);
},
onModelAdd: function(model) {
// do something
}
});
var myCollection = new MyCollection();
var myView = new MyView({collection: myCollection});