VOOZH about

URL: https://www.geeksforgeeks.org/javascript/backbone-js-fetch-collection/

⇱ Backbone.js fetch Collection - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Backbone.js fetch Collection

Last Updated : 26 Jul, 2022

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.

Output:

👁 Image
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.

Output:

👁 Image
Backbone.js fetch Collection

Reference: https://backbonejs.org/#Collection-fetch

Comment