Created
December 3, 2015 06:38
-
-
Save zeckdude/a16968b2dc2734e459dc to your computer and use it in GitHub Desktop.
Backbone from Scratch Chapter Project: Collections
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// BACKBONE COLLECTIONS PROJECT | |
console.log("Begin - BACKBONE COLLECTIONS PROJECT"); | |
// Create a Backbone collection for the Vehicle model you created in the last project. | |
var Cars = Backbone.Collection.extend({ | |
model: Vehicle | |
}); | |
// Add the following cars inside the collection: | |
// * car1: { registrationNumber = “XLI887”, colour = “Blue” } | |
// * car2: { registrationNumber = “ZNP123”, colour = “Blue” } | |
// * car3: { registrationNumber = “XUV456”, colour = “Gray” } | |
var cars = new Cars([ | |
new Car({ registrationNumber: "XLI887", color: "Blue" }), | |
new Car({ registrationNumber: "ZNP123", color: "Blue" }), | |
new Car({ registrationNumber: "XUV456", color: "Gray" }) | |
]); | |
// Find all the Blue colours and log them in the console. | |
console.log(cars.where({ color: "Blue" })); | |
// Find the car with the registration number XLI887 and log it in the console. | |
var carWithSpecifiedRegistrationNumber = cars.findWhere({ registrationNumber: "XLI887" }); | |
console.log(carWithSpecifiedRegistrationNumber); | |
// Remove this car from the collection. | |
cars.remove(carWithSpecifiedRegistrationNumber); | |
// Convert the collection to a JSON object and log it in the console. | |
console.log(cars.toJSON()); | |
// Iterate the collection and log each car in the console. | |
cars.each(function(car) { | |
console.log(car); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment