The event is not triggered on the collection, because the room
model is not associated (i.e. has not been added) to this.collection
.
Assuming you have defined your model
and collection
similar to:
var Room = Backbone.Model.extend();
var Rooms = Backbone.Collection.extend({
model:Room
});
var rooms = new Rooms();
rooms.on('all',function(eventName) {
console.log(eventName);
});
For your code to work as expected you would have to add
the room
model to the rooms
collection such as:
var room = new Room({'name':'hello'});
// This will trigger the add event on the collection
rooms.add(room);
// save the model
room.save();
The following is short-hand for the above code block:
var room = rooms.create({'name':'hello'});
Here is a FIDDLE showing the behavior.