Skip to main content

wondering about top-level persistence of a netsted object in backbone

✓ Published0🌍 Public
Aamundo
Last edited Sep 30, 2012
Created on Sep 30, 2012

This example demonstrates a nested Backbone.js data model where a `Text` model contains a `SentenceCollection`, while the top-level `TextCollection` persists to `localStorage` via `Backbone.LocalStorage`. The code shows `Text` initializing its own `SentenceCollection` in the model’s `initialize` method, but leaves `Sentence` and `SentenceCollection` without any persistence layer, prompting a question about whether to override `Sentence.save` to hand data upward. It uses Backbone’s `Model.extend` and `Collection.extend` to define the hierarchy, illustrating the challenge of persisting nested collections through a single top-level store.

AI-generated description