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.
Solution: Create a new model and watch when it changes - Backbone.js Tutorial
From the course: Learning Backbone.js
Solution: Create a new model and watch when it changes
Let's take a look and see how I approach the challenge. First, I created a collection called EuropeanFlower inside of js > collections > allFlowers.js. I made sure to assign my app.singleFlower model to this collection. I then went over to my singleFlowerModel.js file and added an initialized method starting on line 6. I'm using this.on on line 8 to watch for any instance changes of any kind. When a change is applied, it should send a message to my browser console, informing me of the change. Now I chose to use the this.get method on line 9 to display the instance name in my message, but this wasn't a requirement for this challenge. It was more important that you actually get a message to display in the console. The words you use to make up your message were not important. Next, I created the tantalizingTulips and fleurDeLis model instances inside of js > flowerApp.js. I made sure that their names were clear and related to my variable instance names, but you could have used any…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.