VOOZH about

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

⇱ Backbone.js model Collection - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Backbone.js model Collection

Last Updated : 12 Dec, 2022

The Backbone.js model Collection is the property that specifies the model collection. If this property is defined then we can pass objects, an array of objects, and uses options add, create and reset then the attributes will be converted into a model of the proper type using provided options. 

Syntax:

collection. model( attrs, options ) ;

Parameters: 

  • attrs: These are the attributes of the model passed. 
  • options: These are the optional parameter that is passed to the model when creating a model with attrs. 

Example 1: In this example, we will illustrate the Backbone.js model Collection. We will define the model property of the collection which has default attributes and write them in the document.

Output:

👁 Image
Backbone.js model Collection

Example 2: In this example, we will define the polymorphic model for the collection. Polymorphic model are model which are defined according to the condition which are attributes present in the model. 

Output:

👁 Image
Backbone.js model Collection

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

Comment