From the course: Learning Backbone.js

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Creating a collection of models

Creating a collection of models - Backbone.js Tutorial

From the course: Learning Backbone.js

Start my 1-month free trial

Creating a collection of models

Backbone collections are simple to describe. A collection is a group of model instances. That's it, I'm done describing them. They are powerful and contain a lot of built in functionality, but in terms of explaining what they are, that really is it. A collection is a group of model instances. In this video, we'll go through the steps of creating a collection. And then, review how to add model instances to the collection, as well as remove them. To create a collection, you first have to let it know which model it's based on. This is a must. A collection will not work if you skip this step. From there, you can add model instances to it in a few different ways. You can either add the instances as parameters to your collection instance with the help of a JavaScript array. Or you can add them one by one using a collections internal.add method. Collections also have an internal.remove method that does as you would expect. It removes model instances from a given collection. Now, I won't be…

Contents