JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://documentcloud.github.com/underscore/underscore.js"></script>
<script src="http://documentcloud.github.com/backbone/backbone.js"></script>
<script src="https://raw.github.com/PaulUithol/Backbone-relational/master/backbone-relational.js"></script>
JavaScript
// MODELS
SurveyTreeNode = Backbone.RelationalModel.extend({
relations: [{
type: Backbone.HasMany,
key: 'questions',
relatedModel: 'SurveyTreeNode'
}]
});
var survey = {
id: 1,
questions: [
{
id: 2,
text: 'What is your name?'
},
{
id: 3,
text: 'What hours do you work?',
questions: [
{
id: 3,
text: 'On Monday?'
},
{
id: 4,
text: 'On Tuesday?'
}
]
}
]
};
var questionTree = new SurveyTreeNode(survey);
console.log(questionTree.toJSON())