渲染木偶区模型已经被抓走后, [英] Render a Marionette region after model has been fetched

查看:161
本文介绍了渲染木偶区模型已经被抓走后,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用由德里克·贝利所描述的方法一个通用的问题解决方案在这个<一个href=\"http://stackoverflow.com/questions/10643474/binding-a-backbone-model-to-a-marionette-itemview-blocking-fetch\">thread渲染视图后一种模式是牵强。我会在这里报告了他的解决方案:

I would like to use the approach described by Derick Bailey in "A Generic Problem Solution" in this thread to render a view after a model is fetched. I will report his solution here:

 MyView = Backbone.View.extend({
  initialize: function(){
    this.model.on("sync", this.render, this);
  },

  render: function(){ ... }
});


myModel = new MyModel({id: someId});
new MyView({
  model: myModel
});

myModel.fetch();

我有一个稍微不同的情况:我的看法是一个区域的布局中。如果我所说的Marionette.Region.show()它的工作原理,但视图渲染两次。调用Marionette.Region.attachView()视图呈现的函数被调用一次,但该内容未在页面中显示。

I have a slightly different situation: my view is inside a region layout. If I call the Marionette.Region.show() it works but the view is rendered twice. Calling Marionette.Region.attachView() the view render's function is called once but the content is not displayed in the page.

任何想法?

推荐答案

您可以等到模型渲染视图前同步时间

You can wait until the model is sync'd before rendering the view


var myView = new MyView({
  model: myModel
});

myModel.on("sync", function(){
  myRegion.show(myView);
});

myModel.fetch();

这篇关于渲染木偶区模型已经被抓走后,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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