Backbone.js fetch Collection Last Updated : 26 Jul, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report The Backbone.js fetch Collection is used to fetch the set of models from the server for collection. When the models are returned models are merged with the existing models. If we want to reset all the models and form fill new models we use { reset: true } option of this method which resets the collection. Syntax: collection.fetch( options ); Parameters: options: This option hash takes success and error callbacks which will be in case of status of response from the server. Example 1: In this example, we will illustrate the Backbone.js fetch Collection. Here we will use the fetch() method and which will call the sync method of the collection which will print the models of the collection. HTML <!DOCTYPE html> <html> <head> <title>BackboneJS fetch Router</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" type="text/javascript"> </script> </head> <body> <h1 style="color: green;"> GeeksforGeeks </h1> <h3>BackboneJS fetch Router</h3> <script type="text/javascript"> var Book = Backbone.Model.extend(); var b1 = { title: "Ram", Author: "Amish Tripathi", vol: 1 }; var b2 = { title: "Lolita", Author: "Vladimir Nabokov", vol: 2 }; var b3 = { title: "The Palace of Illusion", Author: "Chitra Banerjee", vol: 1 }; var books = Backbone.Collection.extend({ model: Book, }); var Library = new books([b1, b2, b3]); Backbone.sync = function (method, model) { for (let x of model.models) document.write(JSON.stringify(x), '<br>'); }; Library.fetch(); </script> </body> </html> Output: Backbone.js fetch Collection Example 2: In this example, we will fetch the data from the API and parse the data and get the username from each data. HTML <!DOCTYPE html> <html> <head> <title>BackboneJS fetch collection</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.2.2/backbone-min.js" type="text/javascript"> </script> </head> <body> <h1 style="color: green;"> GeeksforGeeks </h1> <h3>BackboneJS fetch collection</h3> <div id='para'></div> <script type="text/javascript"> function user_Name(user) { console.log(user.username); } var post = Backbone.Model.extend(); var posts = Backbone.Collection.extend({ model: post, url: "jsondata/users", parse: function (response, options) { _.each(response, user_Name); } }); var comments = new posts(); comments.fetch(); </script> </body> </html> Output: Backbone.js fetch Collection Reference: https://backbonejs.org/#Collection-fetch Comment More infoAdvertise with us Next Article Backbone.js get Collection S satyam00so Follow Improve Article Tags : JavaScript Web Technologies Backbone.js Backbone.js Collection Similar Reads Backbone.js get Collection The Backbone.js get Collection is used  to retrieve model from a Collection. This method uses unique identified to get the model we can use user define id value or by default cid value or model name. Syntax: collection.get ( id ); Parameters: id: It is a unique identifier that is used to identify 2 min read Backbone.js extend Collection In this article, we will see the Backbone.js extend collection. The Backbone.js extend collection can be used to extend the backbone's collection class in which we can create our own collection. It also facilitates the instance properties & the optional classProperties that are attached to the c 2 min read Backbone.js create Collection The Backbone.js create Collection is used to create an instance of model inside of collection. The Create method of Collection is equivalence to instantiating a model, saving the model to the server and adding model to set after successfully creation and save model to server. If the validation of mo 2 min read Backbone.js Collections A Backbone.js Collections are a group of related models. It is useful when the model is loading to the server or saving to the server. Collections also provide a helper function for performing computation against a list of models. Aside from their own events collections also proxy through all of the 2 min read Backbone.js findWhere Collection In this article, we will discuss the Backbone.js findWhere collection. The Backbone.js findWhere collection is used to retrieve and return the first value with the specified matched attribute in the given model array of collection. Syntax: Backbone.Collection.findWhere(attribute) Parameter: It takes 2 min read Backbone.js at Collection In this article, we will discuss Backbone.js at collection. The Backbone.js at collection is used to return the model from the given collection by specifying the index. Indexing starts with 0. Syntax: collection.at(models,options) Parameters: It will take two parameters. models: this is the first pa 3 min read Like