Skip to content

Instantly share code, notes, and snippets.

Created June 19, 2012 11:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/2953670 to your computer and use it in GitHub Desktop.
Save anonymous/2953670 to your computer and use it in GitHub Desktop.
Backbone.js Collection fetchMany()
var Equipment = {};
Equipment.Model = Backbone.Model.extend({
urlRoot: 'equipment',
defaults: {
//...
}
});
Equipment.Collection = Backbone.Collection.extend({
url: 'equipment/list',
model: Equipment.Model,
fetchMany: function(id_list) {
var that = this;
Backbone.sync('create', new Backbone.Model({id_list: id_list}), {
url: that.url,
success: function(response_data) {
var models = [];
for (i=0; i<response_data.length; i++) {
models.push(new that.model(response_data[i]));
}
that.reset(models);
return true;
},
error: function() {
// handle error
}
});
}
});
var my_equipment_list = new Equipment.Collection();
my_equipment_list.fetchMany([12, 345, 234, 55, 23]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment