jQuery.Model.static.create  function     

Source

Create is used to create a model instance on the server. By implementing create along with the rest of the service api, your models provide an abstract API for services.

Create is called by save to create a new instance. If you want to be able to call save on an instance you have to implement create.

The easiest way to implement create is to just give it the url to post data to:

$.Model("Recipe",{
  create: "/recipes"
},{})

This lets you create a recipe like:

new Recipe({name: "hot dog"}).save(function(){
  this.name //this is the new recipe
}).save(callback)

You can also implement create by yourself. You just need to call success back with an object that contains the id of the new instance and any other properties that should be set on the instance.

For example, the following code makes a request to '/recipes.json?name=hot+dog' and gets back something that looks like:

{ 
  id: 5,
  createdAt: 2234234329
}

The code looks like:

$.Model("Recipe", {
  create : function(attrs, success, error){
    $.post("/recipes.json",attrs, success,"json");
  }
},{})

API

$.Model.create(attrs, success(attrs), error)
{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.

� Jupiter Consulting - JavaScriptMVC Training and Support