- BackboneJS Tutorial
- BackboneJS - Home
- BackboneJS - Overview
- BackboneJS - Environment Setup
- BackboneJS - Applications
- BackboneJS - Events
- BackboneJS - Model
- BackboneJS - Collection
- BackboneJS - Router
- BackboneJS - History
- BackboneJS - Sync
- BackboneJS - View
- BackboneJS - Utility
- BackboneJS Useful Resources
- BackboneJS - Quick Guide
- BackboneJS - Resources
- BackboneJS - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
BackboneJS - Model
The following table lists down all the methods which you can use to manipulate the BackboneJS-Model −
|S.No.||Methods & Description|
It extends the backbone.Model class while creating your own backbone Model.
When a model instance is created, the class's constructor gets called and it is invoked by defining the initialize function when the model is created.
It gets the value of an attribute on the model.
It sets the value of an attribute in the model.
It is like the get function, but returns the HTML-escaped version of a model's attribute.
Returns true, if attribute value defined with non-null value or non-undefined value.
It removes an attribute from a backbone model.
Removes all attributes, including id attribute from a backbone model.
It uniquely identifies the model entity, that might be manually set when a model is created or populated or when a model is saved on the server.
Defines a model's unique identifier which contains the name of the member of the class which will be used as id.
It is an auto generated client id by Backbone which uniquely identifies the model on the client.
Attributes defines property of a model.
Changes all the attributes that have changed after setting the attributes using the set() method.
Sets a default value to a model, that means if the user doesn't specify any data, the model won't fall with an empty property.
Returns a copy of the attributes as an object for JSON stringification.
It is used to communicate with the server and to represent the state of a model.
Accept the data from the server by delegating sync() method in the model.
Saves the data of the model by delegating to sync() method which reads and saves the model every time when a Backbone calls it.
Destroys or removes the model from the server by using the Backbone.sync method which delegates the HTTP "delete" request.
If the input is invalid, it returns a specified error message or if the input is valid, it doesn't specify anything and simply displays the result.
It displays the validation error, if the validation fails or after the invalid event is triggered.
It checks the model state by using the validate() method and also checks validations for each attribute.
It is used for the instance of the model and returns the url to where the model's resource is located.
Enables the url function by using the model id to generate the URL.
Returns the model's data by passing through the response object and represents the data in the JSON format.
It is used to create a deep copy of a model or to copy one model object to another object.
Returns true, if the attribute gets changed since the last set.
Determines whether the model is a new or an existing one.
It returns the model's attributes that have changed since the last set or else becomes false, if there are no attributes.
It determines the previous value of the changed attribute.
Returns the state of the all the attributes prior to the last change event.
There are six Underscore.js methods which provides their functionality to be used on the Backbone.Model.
|S.No.||Methods & Description|
It is used to access the object's enumerable properties.
It is used to get values of object's properties.
It describes the object's properties in terms of key value pairs.
It returns the copy of object, in which keys have become the values and vice versa.
It returns the copy of object and indicates which keys to pick up.
It returns the copy of object and indicates which keys to omit.