Just starting to dip my toes into the world of Backbone.js and I feel like I'm getting the hang of it.
A little context: I recently built an interactive quiz using jQuery and Handlebars, but now I want to transition it over to Backbone. The Quiz pulls all its questions from a static allQuestions.json file in the same directory. Here's what the file structure looks like:
{
"Q1" : {"question": "Who is the true Admin of the HON chat?",
"choices": ["Kattigpelika", "Bangan", "Naldor"],
"correctAnswer": 0},
"Q2" : {"question":"Who is the chat's true mad son?",
"choices": ["Bangan","Grev3n","Mettapod"],
"correctAnswer": 1
}
ETC...
(The format is correct as I have used it before with $.getJSON)
My current focus is on creating a Model:
var Question = Backbone.Model.extend({
initialize: function(){
console.log("Model created");
}
});
that integrates into the Collection:
var Questions = Backbone.Collection.extend({
model: Question,
url: "allQuestions.json"
});
I am attempting to use the function:
allQuestions.fetch({
success: function(){
console.log(allQuestions);
}
});
To generate a new model for each object in the .json file and add it to the collection. Is this doable? Or am I missing something?
All of this is running on my local machine.