Easy learning with example program codes

Backbone.js Model

Being the heart of any Javascript application, the models are known to be the most important building blocks for the creation of Javascript applications. The core of a JavaScript application is a Model. The data is retrieved and is populated by the model. A Model is a representation of a basic data object in the framework and is also a representation of the business entities with some business logic and business validations which is used for data storage and business logic. There are methods to modify the models in Backbone.JS. All the Backbone.JS Model’ methods are listed below:


attributesTo define the property of a model.
changedTo change all the attributes that have changed by using set() method.
changedAttributesTo return the model’s attributes that have changed since the last set or becomes false, if there is no attribute.
cidTo uniquely identify the model on the client.
clearTo remove all attributes, which also includes the id attribute from a backbone model.
cloneTo create a deep copy of a model or to copy one model object to another object.
defaultsTo set a default value to a model.
destroyTo destroy or remove the model from the server.
escapeTo get the html-escaped version of a model’s attributes.
extend To extend Backbone.model class while creating a backbone model.
fetchTo accept the data from the server by delegating sync() method in the model.
getTo get the value of an attribute in the model.
hasTo get a true value, if the attribute value is defined with a non-null value or non-undefined value.
hasChangedTo return TRUE, if the attributes have changed since the last set.
idTo identify model entity uniquely.
idattributeTo specify the model’s unique identifier.
initializeTo invoke the class’s constructor when model is created.
isNewTo determine whether the model is a new or existing one.
isValidTo checks the model state and to check validations for each attribute.
parseTo return the model’s data by passing through the response object
previousTo determine the previous value of the changed attribute.
previousAttributesTo return state of the all attributes prior to last change event.
saveTo save the data of the model.
setTo set the value of an attribute in the model.
syncTo communicate with the server and to represent state of a model.
toJSON To get a copy of the attributes as an object for JSON stringification.
unsetTo remove an attribute from a backbone model.
urlTo return URL where model’s resource is located.
urlRootTo enable the URL function.
validateTo validate the input before displaying the result.
validationErrorTo display an error, if validation fails or after the invalid event is triggered.



Please follow and like us:
Posted in Java   

Copyright © 2020 CodesJava Protection Status