- BackboneJS - Utility
- BackboneJS - View
- BackboneJS - Sync
- BackboneJS - History
- BackboneJS - Router
- BackboneJS - Collection
- BackboneJS - Model
- BackboneJS - Events
- BackboneJS - Applications
- BackboneJS - Environment Setup
- BackboneJS - Overview
- BackboneJS - Home
BackboneJS Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
BackboneJS - Model
Models contain dynamic data and its logic. Logic such as conversions, vapdations, computed properties and access control fall under the Model category. As it contains all the apppcation data, a model is also called as the heart of JavaScript apppcation.
The following table psts down all the methods which you can use to manipulate the BackboneJS-Model −
S.No. | Methods & Description |
---|---|
1 |
It extends the backbone.Model class while creating your own backbone Model. |
2 |
When a model instance is created, the class s constructor gets called and it is invoked by defining the initiapze function when the model is created. |
3 |
It gets the value of an attribute on the model. |
4 |
It sets the value of an attribute in the model. |
5 |
It is pke the get function, but returns the HTML-escaped version of a model s attribute. |
6 |
Returns true, if attribute value defined with non-null value or non-undefined value. |
7 |
It removes an attribute from a backbone model. |
8 |
Removes all attributes, including id attribute from a backbone model. |
9 |
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. |
10 |
Defines a model s unique identifier which contains the name of the member of the class which will be used as id. |
11 |
It is an auto generated cpent id by Backbone which uniquely identifies the model on the cpent. |
12 |
Attributes defines property of a model. |
13 |
Changes all the attributes that have changed after setting the attributes using the set() method. |
14 |
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. |
15 |
Returns a copy of the attributes as an object for JSON stringification. |
16 |
It is used to communicate with the server and to represent the state of a model. |
17 |
Accept the data from the server by delegating sync() method in the model. |
18 |
Saves the data of the model by delegating to sync() method which reads and saves the model every time when a Backbone calls it. |
19 |
Destroys or removes the model from the server by using the Backbone.sync method which delegates the HTTP "delete" request. |
20 |
If the input is invapd, it returns a specified error message or if the input is vapd, it doesn t specify anything and simply displays the result. |
21 |
It displays the vapdation error, if the vapdation fails or after the invapd event is triggered. |
22 |
It checks the model state by using the vapdate() method and also checks vapdations for each attribute. |
23 |
It is used for the instance of the model and returns the url to where the model s resource is located. |
24 |
Enables the url function by using the model id to generate the URL. |
25 |
Returns the model s data by passing through the response object and represents the data in the JSON format. |
26 |
It is used to create a deep copy of a model or to copy one model object to another object. |
27 | Returns true, if the attribute gets changed since the last set. |
28 |
Determines whether the model is a new or an existing one. |
29 |
It returns the model s attributes that have changed since the last set or else becomes false, if there are no attributes. |
30 |
It determines the previous value of the changed attribute. |
31 |
Returns the state of the all the attributes prior to the last change event. |
Underscore Methods
There are six Underscore.js methods which provides their functionapty to be used on the Backbone.Model.
S.No. | Methods & Description |
---|---|
1 |
_.keys(object) It is used to access the object s enumerable properties. |
2 |
_.values(object) It is used to get values of object s properties. |
3 |
_.pairs(object) It describes the object s properties in terms of key value pairs. |
4 |
_.invert(object) It returns the copy of object, in which keys have become the values and vice versa. |
5 |
_.pick(object, *keys) It returns the copy of object and indicates which keys to pick up. |
6 |
_.omit(object, *keys) It returns the copy of object and indicates which keys to omit. |