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 FindWhere() collection

The Backbone.JS FindWhere() collection method is used to get the first model that matches the specified attribute in the collection. Syntax: Collection.FindWhere ( attribute ) Parameters: attribute: This parameter is used to specify the attribute of a model in a collection. Example: <!DOCTYPE html> <html> <head> <title>Example</title> <script src="https://code.jquery.com/jquery-2.1.3.min.js" type="text/javascript"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.2/underscore-min.js" type="text/javascript"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.2/backbone-min.js" … Read more

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

Backbone.JS Comparator()

The Backbone.JS Comparator() collection method is used to sort the items in the collection. Syntax: Collection.Comparator 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 Comparator() method maintains the collection in sorted order based on the value of the ‘id’.