I have notifications in my Rails & Backbone.js app
// MODEL
NotificationModel = App.BB.Model.extend({
defaults : {}
});
// COLLECTION
NotificationCollection = App.BB.Collection.extend({
model: NotificationModel,
url: '/notifications',
initialize : function() {
var me = this;
me.fetch();
}
});
The model has the following fields (id, read) where read is true or false.
What I want to do is once the user views the notifications, mark all as READ = true on the server. What’s the right way to do that with Backbone.js?
Thanks
There is no Bulk upload in Backbone.js
so you have two choices
continue to work as backbone does best,
you can update every model in your collection to set the item as read.
this will post the model to the server and update your server (for that model only)
yes, this might seem heavy but backbone works this way, there is no bulk update of models (yet?)
the other solution is to post it yourself usign a custom made Ajax call,
for example this jQuery call.
keep in mind that: after this ajax call is complete you might want to fetch your collection again to update it (otherwise the models in your collection will don’t know about the changes yo u did to the server, so all models will list
read: truein their changedAttributes.