In my backbone.Marionette application I have a Model that requires an Id attribute to construct it’s url. I therefore create the model by passing it an Id, add it to a view and then fetch the model:
model = new Model({_id:id})
view = new View({model:model})
app.content.show(view)
model.fetch()
I would expect the view to only start rendering once the model has been fetched, but Marionette renders the model immediately causing my template rendering to fail as the expected attributes don’t exist. Any workarounds?
I’m trying to do something similar to the accepted answer here:
Binding a Backbone Model to a Marionette ItemView – blocking .fetch()?
But while that works with backbone, as stated in the answer, Marionette automatically renders the view.
Also see:
Backbone Marionette Displaying before fetch complete
If you truly want to prevent rendering until the model has been fetched you should reorder your calls like this:
Alternatively, you should think about rendering immediately and taking advantage of Marionette’s blank state support.