model.parse

parsemodel.parse(response, options) parse is called whenever a model's data is returned by the server, in fetch, and save. The function is passed the raw response object, and should return the attributes hash to be set on the model. The default implementation is a no-op, simply passing through the JSON response. Override this if you need to work with a preexisting API, or better namespace your responses. If you're working with a Rails backend that has a version prior to 3.1, you'll notice th

model.pairs

pairs

model.omit

omit

model.keys

keys

model.isValid

isValidmodel.isValid() Run validate to check the model state. var Chapter = Backbone.Model.extend({ validate: function(attrs, options) { if (attrs.end < attrs.start) { return "can't end before it starts"; } } }); var one = new Chapter({ title : "Chapter One: The Beginning" }); one.set({ start: 15, end: 10 }); if (!one.isValid()) { alert(one.get("title") + " " + one.validationError); }

model.isNew

isNewmodel.isNew() Has this model been saved to the server yet? If the model does not yet have an id, it is considered to be new.

model.isEmpty

isEmpty

model.invert

invert

model.idAttribute

idAttributemodel.idAttribute A model's unique identifier is stored under the id attribute. If you're directly communicating with a backend (CouchDB, MongoDB) that uses a different unique key, you may set a Model's idAttribute to transparently map from that key to id. var Meal = Backbone.Model.extend({ idAttribute: "_id" }); var cake = new Meal({ _id: 1, name: "Cake" }); alert("Cake id: " + cake.id);

model.id

idmodel.id A special property of models, the id is an arbitrary string (integer id or UUID). If you set the id in the attributes hash, it will be copied onto the model as a direct property. Models can be retrieved by id from collections, and the id is used to generate model URLs by default.