获取模型后渲染木偶区域 [英] Render a Marionette region after model has been fetched

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

问题描述

我想使用 Derick Bailey 在此 线程 在获取模型后呈现视图.我会在这里报告他的解决方案:

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天全站免登陆