动态添加地区木偶布局 [英] Dynamically add regions to Marionette layout

查看:150
本文介绍了动态添加地区木偶布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个布局,但因为它们不是已知无法定义预先其所有区域。

I have a layout, but cannot define all of its regions in advance because they are not known.

所以后来的ItemView控件创建,我想使用视图的ID作为区域的名称在布局中创建一个新的区域,所以我可以然后说:

So later on an ItemView is created and I'd like to create a new region in the layout using the view's ID as the region's name so I can then say:

layout.dynamicRegionName.show(newItemView);

但这里存在循环依赖。

But there is cyclic dependency here.


  1. 我没有渲染的看法,所以我不能让在布局的号召,用于.addRegion到DOM元素的引用()

  1. I haven't rendered the view yet, so I cannot make a reference to its DOM element to be used in the layout's call to .addRegion()

我无法呈现它,precisely,因为我希望它得到重视通过动态添加区域DOM树通过调用.show()

I cannot render it, precisely because I want it to get attached to the DOM tree through the dynamically added region by calling its .show()

@DerickBailey在GitHub上Marionette.Layout文档我相信这是在具有例如一个错误: layout.show(新MenuView());

@DerickBailey In the Marionette.Layout docs in github I believe there is an error in the example that has: layout.show(new MenuView());

但在技术上,这是接近我们需要在这里即如何能够做到:

but technically this is close to what we'd need here i.e. to be able to do:

layout.addRegion(VAR_WITH_NEW_REGION_NAME, aViewInstance);

和有这种添加一个新的区域到布局呈现里面直接视图实例。

and have this add a new Region into the layout rendering inside it directly the view instance.

我缺少其他一些明显的方式来实现这一目标?那是一个已知的缺少的功能?有没有理由不拥有它?

Am I missing some other obvious way to achieve this? Is that a known missing functionality? Is there a reason not to have it?

我知道这previous问:<一个href=\"http://stackoverflow.com/questions/12868494/dynamically-add-remove-regions-to-a-layout\">Dynamically添加/删除地区布局
但没有看到任何明确的/肯定的答案吧。

I'm aware of this previous Q: "Dynamically add/remove regions to a layout" but don't see any clear/definite answer to it.

推荐答案

木偶V1.0(V1.0.2最新的是,现在)支持动态的布局区域。

Marionette v1.0 (v1.0.2 is latest, right now) supports dynamic regions in Layouts.


var MyLayout = Marionette.Layout.extend({
  template: "#some-template"
});

var layout = new MyLayout();
layout.render();

layout.addRegion("someRegion", "#some-element");

layout.someRegion.show(new MyView());

这篇关于动态添加地区木偶布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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