JSFiddle - React, Tailwind, and code Playground
HTML
<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.3/underscore-min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/backbone.js/0.9.10/backbone-min.js"></script>
JavaScript
var ControlCollection, ControlModel, controls, p;
ControlModel = (function() {
class ControlModel extends Backbone.Model {
initialize() {
return this.set('controls', new ControlCollection(this.get('controls')));
}
};
//Strucuture of builder page model
ControlModel.prototype.defaults = {
name: '',
controls: []
};
return ControlModel;
}).call(this);
ControlCollection = (function() {
class ControlCollection extends Backbone.Collection {};
ControlCollection.prototype.model = ControlModel;
return ControlCollection;
}).call(this);
controls = [
{
name: "container",
controls: [
{
name: "dropdown",
controls: []
}
]
}
];
p = new ControlCollection(controls);
console.log("normal collection",p);
console.log("json collection", p.toJSON())