How to prevent Backbone.Marionette from rendering a view if it's model hasn't been fetched?

前端 未结 4 656
暗喜
暗喜 2020-12-31 10:08

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

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-31 10:22

    If you truly want to prevent rendering until the model has been fetched you should reorder your calls like this:

    model = new Model({_id:id});
    view = new View({model:model});
    model.fetch({success: function () {
      app.content.show(view);
    });
    

    Alternatively, you should think about rendering immediately and taking advantage of Marionette's blank state support.

提交回复
热议问题