如何从渲染视图,如果它的模式一直没有牵强prevent Backbone.Marionette? [英] How to prevent Backbone.Marionette from rendering a view if it's model hasn't been fetched?

查看:91
本文介绍了如何从渲染视图,如果它的模式一直没有牵强prevent Backbone.Marionette?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我backbone.Marionette应用程序,我有一个需要Id属性来构建它的URL模型。因此,我通过它传递一个id创建模型,将其添加到视图,然后取模型:

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?

我试图做同样的在这里接受的答案的东西:
<一href=\"http://stackoverflow.com/questions/10643474/binding-a-backbone-model-to-a-marionette-itemview-blocking-fetch\">Binding一个骨干模型木偶ItemView控件 - 阻塞.fetch()

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.

另见:
<一href=\"http://stackoverflow.com/questions/11317691/backbone-marionette-displaying-before-fetch-complete\">Backbone木偶显示之前获取完整的

推荐答案

如果你真的想prevent渲染,直到模型被取出,你应该重新安排你的电话是这样的:

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.

这篇关于如何从渲染视图,如果它的模式一直没有牵强prevent Backbone.Marionette?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆