How to update model in collection?
backbone.js
Solution
I've also recently wanted to update particular model in the collection. The problem was that if I did use just `model.save` it didn't update the collection. The goal was to change the model in collection, change it on the server, update collection accordingly and not use the `sync` method. So for example I have my variable `collection` and I want to change the model with `id = 2`. So the first thing, I will create an instance model, like this: `var model = collection.get(2)` Then I will update the attributes on this particular model: `model.set({name: 'new name'})` Then I will save it to the server: `model.save({}, {url:'/api/v1/tags/'+model.get('id')})` Then we have to update collection accordingly to the changes: `collection.set({model},{remove: false})` `set` method - it's a 'smart' update of the collection with the list of the models you passed in parameters. `remove: false` parameter - it's a restriction for a collection to remove existing models in collection. More here.
Problem
I have the following Backbone.js collection: ``` var Tags = Backbone.Collection.extend({ url: "/api/v1/tags/" }), ``` How do I update one of the models in the collection so that it posts to /api/v1/tags/id and saves the data for that model. So if I change name of model with id 2 in the collection It should PUT to /api/v1/tags/2 with the following data: name: new name id: 2