Best practice for saving an entire collection?

Usually REST backends handle single instance creation/update. You would need to change that to accept an array of objects. That said, on the client side, you would need to go directly to the Backbone.sync function Backbone.sync = function(method, model, options) In this case your model should be an array of model. The method should be … Read more

Filter backbone collection by attribute value

I like returning a new instance of the collection. This makes these filtering methods chainable (boxes.byColor(“red”).bySize(“L”), for example). var Boxes = Backbone.Collection.extend({ model: Box, byColor: function (color) { filtered = this.filter(function (box) { return box.get(“color”) === color; }); return new Boxes(filtered); } }); var red_boxes = boxes.byColor(“red”)

How to find a model from a collection according to some attribute other than the ID?

For simple attribute based searches you can use Collection#where: where collection.where(attributes) Return an array of all the models in a collection that match the passed attributes. Useful for simple cases of filter. So if friends is your Friends instance, then: var lees = friends.where({ name: ‘Lee’ }); There’s also Collection#findWhere (a later addition as noted … Read more