model
can.Model.model
Convert raw data into a can.Model instance.
can.Model.model(data)
Parameters
-
data
{Object}
The data to convert to a can.Model instance.
Returns
{can.Model}
An instance of can.Model made with the given data.
model: "PROPERTY"
Creates a model
function that looks for the attributes object in the PROPERTY
property of raw instance data.
can.Model.model(attributes)
is used to convert data from the server into a model instance. It is rarely called directly. Instead it is invoked as a result of findOne or findAll.If your server is returning data in non-standard way, overwriting
can.Model.model
is a good way to normalize it.Example
The following uses
model
to convert to a model instance.Task.model(attrs)
is very similar to simply callingnew Model(attrs)
except that it checks the model's store if the instance has already been created. The model's store is a collection of instances that have event handlers.This means that if the model's store already has an instance, you'll get the same instance back. Example:
Non-standard Services
can.Model.model
expects to retreive attributes of the model instance like:If the service returns data formatted differently, like:
Overwrite
model
like: