I have a Backbone app that uses nested collections (at least that's how I think they're called).
In my particular case there are tabs and subtabs, and each tab (model) contains a collection of subtab (model).
For those who're more familiar with code, I'll write bellow my models and collections, and how subtabs are nested inside the tab model:
// Subtab Model
var Subtab = Backbone.Model.extend({
defaults: { label: undefined }
});
// Subtabs Collection
var Subtabs = Backbone.Collection.extend({
model: Subtab
});
// Tab Model
var Tab = Backbone.Model.extend({
defaults: { label: undefined, subtabs: new Subtabs}
});
// Tabs Collection
var Tabs = Backbone.Collection.extend({
model: Tab
});
Now, when I change a tab's attribute it fires the change event on the Tab
model and also on the Tabs
collection (quite normal, right?), but when I change a subtab's attribute, it fires the change event on the Subtab
model and Subtabs
collection (this is also normal) but it doesn't bubble up to the Tab
model (and to the Tabs
collection).
At least, I guess it should because a collection inside a model was changed and so the model was changed (but maybe I'm wrong and I'm not getting it).
Any suggestion on how can I achieve this behavior with Backbone?