I’m new to Backbone.
Is it possible to define a Model in backbone which contains a list of Models of the same type? Example:
MyModel = Backbone.Model.extend({
initialize: function() {
nestedMyModels:new Array();
},
addMyModel: function(aModel) {
// Code here would push() aModel onto array
},
render: function() {
// Loop through array calling render() recursively
}
});
I would then have a View which started a recursive call to render(). Example:
MyView = Backbone.View.extend({
render:function() {
this.model.render();
}
});
1 no arrays but Collections
Always that you think in an
ArrayofModelsin Backbone think in aCollection.Now what you have to do is implement a Collection of MyModels and keep one instance of it in your MyModel instance.
2 use Views for render
Always that you think in
renderthink in aView.And the recommend way is that if you have a
Collectionand aModelbetter having aViewfor each one. This way the View of the Collection will call the View of the Model in an iteration: