public
anonymous / gist:2953670
Created

Backbone.js Collection fetchMany()

  • Download Gist
gistfile1.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
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]);

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.