Reputation: 110960
I have the following:
// MODEL
NotificationModel = C.BB.Model.extend({
defaults : {
read : false
},
urlRoot : '/notifications'
});
// COLLECTION
NotificationCollection = C.BB.Collection.extend({
model: NotificationModel,
url: '/notifications',
initialize : function() {
var me = this;
me.fetch();
}
});
Later in the view I have:
....
onCollectionAdd : function(m,c,cfg) {
m.set({read: true},{silent: false});
The set is changing the items value but Backbone is not posting the update to the server. Any suggestions? Thanks
Upvotes: 1
Views: 161
Reputation: 110922
You could bind an event to the collection to save them:
NotificationCollection = C.BB.Collection.extend({
model: NotificationModel,
url: '/notifications',
initialize : function() {
this.fetch();
this.bind('change', this.save, this);
}
});
Note there is also the Collection.create
method wich add a new model to the collection and save the collection on the server.
Upvotes: 1
Reputation: 36
You need to call m.save(), which will call correspondent method create() or update().
Method set() trigger only change() event, which not save any data in backend
Upvotes: 2