VOOZH about

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

⇱ Backbone.js modelId Collection - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Backbone.js modelId Collection

Last Updated : 12 Dec, 2022

The Backbone.js modelId Collection is used to uniquely identify the models in the collection. By default, Collection uses idAttribute value of Model to identify the models. We can override our modelId function whose return value will be used by the collection to uniquely identify the Models. 

Syntax:

collection.modeId( attrs, idAttribute );

Parameters: 

  • attrs: These are attributes passed to the models.
  • idAttribute: It is idAttribute of model. 

Example 1: In this example, we will illustrate the Backbone.js modelId Collection. Here we will see the default modelId return idAttribute.

Output:

👁 Image
Backbone.js modelId Collection

Example 2: In this example, we will customize modelId and make a unique identifier with the specified attribute of the model. 

Output:

👁 Image
Backbone.js modelId Collection

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

Comment