model

  • function
can.Model.model  

Deprecated 2.1

Prior to 2.1, .model was used to convert ajax responses into a data format useful for converting them into a can.Model instance AND for converting them into that instance. In 2.1, parseModel should be used to convert the ajax response into a data format useful to model. can.Model.makeFindOne can be used for further customizing how a response is converted into a model instance.

Convert raw data into a can.Model instance. If data's id matches a item in the store's id, data is merged with the instance and the instance is returned.

can.Model.model(data)

Parameters

  1. data {Object}

    The data to convert to a can.Model instance.

Returns

{can.Model}

An instance of can.Model made with the given data.

Use

.models(data) is used to create or retrieve a can.Model instance with the data provided. If data matches an instance in the store, that instance will be merged with the item's data and returneds

For example

Task = can.Model.extend({},{})

var t1 = new Task({id: 1, name: "dishes"})

// Binding on a model puts it in the store
t1.bind("change", function(){})

var task = Task.model({id: 1, name : "dishes", complete : false})

t1 === task //-> true
t1.attr("complete")  //-> false