I’m learning how to use Backbone and Parse to create a survey website.
I’ve seen similar questions on Stack Overflow. However my question is a little different.
On this website the user can make his own survey. Suppose for now that there are two types of questions user can post: multiple choices and free response. I created a backbone Model called Question as follows.
//Question Model
//----------------------
var Question = Parse.Object.extend(
"Question", {
//Default attributes for the todo
defaults: {
content: "What's your name",
type: "free_response",
choices: []
},
initialize: function() {
if (!this.get("content")) {
this.set({"content": this.defaults.content});
}
if (!this.get("type")) {
this.set({"type": this.defaults.type});
}
if (!this.get("choices")) {
this.set({"choices": this.defaults.choices});
}
}
});
So I also want to create QuestionView that can display a question. But it should display multiple choices and free response differently.
So what is the best way to display a Question differently according to its type?
Thanks.
In your questionView template add an
ifstatement:For more on how to use underscore templates see:
http://documentcloud.github.com/underscore/#template