Created
June 19, 2012 11:43
-
-
Save anonymous/2953670 to your computer and use it in GitHub Desktop.
Backbone.js Collection fetchMany()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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