Backbone.JS Router Routes()

The Backbone.JS Router Routes() method defines the URL representation of application’s objects on routers. Syntax: Router.Routes Example: Example Output: Called Route 1. Explanation: In the above example the Routes() method calls the desired route.

Backbone.js Router

The client request is sent by an HTTP client using a router. The main purpose of a router is to route client-side applications. The router uses the URL to connect the client-side applications to actions and events. Thus routing can be simply understood as a URL representation of an application’ objects. To specify an application’ … Read more

Backbone.JS Create()

The Backbone.JS Create() collection method creates a new instance of the model in the collection. Syntax: Collection.Create ( attribute, options ) Parameters: attribute: This parameter is used to specify the attributes of a model in a collection. options: This parameter is used to specify the parameters like id, name, etc. Example: Example Output: {“0″:”create”,”1″:{“name1″:”Happy”,”name2″:”Smiley”},”2″:{“validate”:true,”parse”:true}} Explanation: … Read more

Backbone.JS Fetch()

The Backbone.JS Fetch() collection method extracts the data from the model in a collection. Syntax: Collection.Fetch ( options ) Parameters: options: This parameter is used to specify the “SUCCESS” or “ERROR” callbacks. Example: Example Output: Fetched data: read: [{“id”:100,”name”:”Happy”}] Explanation: In the above example, the Fetch() method retrieves the data of the collection instance ‘values’.

Backbone.JS Clone()

The Backbone.JS Clone() collection method is used to get the shallow copy of the specified object. Syntax: Collection.Clone ( ) Example: Example Output: New Collection’s Instance: “Jerry Jones” Explanation: In the above example, the Clone() method used the Get() method to retrieve the ‘name’ attribute of the model.

Backbone.JS Parse()

The Backbone.JS Parse() collection method is used to get the collection’s data by passing through the response object. Syntax: Collection.Parse ( response, options ) Parameters: response: This parameter is used to specify the array of model attributes. options: This parameter is used to specify whether to represent the data in JSON format or not. Example: … Read more

Backbone.JS URL()

The Backbone.JS URL() collection method creates an instance of the collection. It returns where the resource is located. Syntax: Collection.URL Example: Example Output: URL: /site/12345/page/54321 Explanation: In the above example, the URL() method displays the URL for the “site” model.

Backbone.JS Where()

The Backbone.JS Where() collection method is used to display the model by using the matched attribute in the collection. Syntax: Collection.Where ( attribute ) Parameters: attribute: This parameter is used to specify the attribute of a model in a collection. Example: Example Output: Total matched name attribute:2 Explanation: In the above example, the Where() method … Read more

Backbone.JS Pluck()

The Backbone.JS Pluck() collection method retrieves the attributes from a model in a collection. Syntax: Collection.Pluck ( attribute ) Parameters: attribute: This parameter is used to specify the attribute of a model in a collection. Example: Example Output: Attributes returned on pluck: Joy,Happy,Smiley Explanation: In the above example, the Pluck() method returns the “name” attributes … Read more

Backbone.JS Sort()

The Backbone.JS Sort() collection method is used to sort the items in the collection. Syntax: Collection.Sort (options) Parameters: options: This parameter is used to specify either of the two values: “true” or “false”. True enables the sorting while false disables it. Example: Example Output: Sorted based on id: [{“id”:2,”name”:”Jim”},{“id”:10,”name”:”Tom”},{“id”:33,”name”:”Kim”}] Explanation: In the above example, the … Read more