Nested collection in a model

63 Aufrufe
Direkt zur ersten ungelesenen Nachricht

Jon Skulski

ungelesen,
23.12.2013, 23:07:0823.12.13
an ren...@googlegroups.com
Trying to follow the nested collection pattern found in http://documentcloud.github.io/backbone/#FAQ-tim-toady

e.g.
var Mailbox = Backbone.Model.extend({

  initialize: function() {
    this.messages = new Messages;
    this.messages.url = '/mailbox/' + this.id + '/messages';
    this.messages.on("reset", this.updateCounts);
  },

  ...

});

var inbox = new Mailbox;

// And then, when the Inbox is opened:

inbox.messages.fetch({reset: true})

But not quite sure how to get it to work with fetcher && model/collectionStore. If we just fetch the collection, the model is not stored or retrieved. If we fetch the model, the collection data is not stored. 

I am also running into similar problems if we are just using one off Backbone models. For example if I create a model in the controller and use that to fetch data and create a new collection. Then it is not placed in the store and hydrated in the model. 

Is there a pattern or example I can follow to 'artificially' store models or collections? 

Thanks!
Jon

ma...@analog.fm

ungelesen,
26.12.2013, 06:56:4626.12.13
an ren...@googlegroups.com
Not sure if it's exactly what you need, but I always need to add the app to the model when I instantiate from the view.


I guess this is because the options aren't being passed into the intitalize function

Allen antworten
Antwort an Autor
Weiterleiten
0 neue Nachrichten