...

/

Creating a New File for Collection

Creating a New File for Collection

Learn how to Implement the FilteredCollection functionality by applying a filtering criterion in a new file for our application's contacts.

Let’s create a FilteredCollection object in our Entities module based on Derick Bailey’s code. Its role will be to manage and encapsulate the collection filtering we used in the “Filtering Contacts” chapter. When we instantiate a filtered collection, we’ll need to provide the base collection (containing all the models), as well as a filtering function, like this:

Press + to interact
var filteredContacts = new ContactManager.Entities.FilteredCollection({
collection: contacts,
filterFunction: function(filterCriterion){
return function(contact){
if(contact.get("firstName") === filterCriterion){
return contact;
}
};
}
});

Steps to create a FilteredCollection

We need to follow the steps below to create our FilteredCollection:

Press + to interact
Flowchart for creating a FilteredCollection
Flowchart for creating a FilteredCollection
...