$.Model.update(id, attrs, success(attrs), error)
{String}
the id of the model instance
{Object}
Attributes on the model instance
{Function}
the callback function, it must be called with an object that has the id of the new instance and any other attributes the service needs to add.
{Function}
a function to callback if something goes wrong.
Update is used to update a model instance on the server. By implementing update along with the rest of the service api, your models provide an abstract API for services.
Update is called by jQuery.Model.save or jQuery.Model.update on an existing model instance. If you want to be able to call save on an instance you have to implement update.
The easist way to implement update is to just give it the url to put data to:
This lets you update a recipe like:
If your server doesn't use PUT, you can change it to post like:
Your server should send back an object with any new attributes the model should have. For example if your server udpates the "updatedAt" property, it should send back something like:
You can also implement create by yourself. You just need to call success back with an object that contains any properties that should be set on the instance.
For example, the following code makes a request to '/recipes/5.json?name=hot+dog' and gets back something that looks like:
The code looks like:
API