动态地添加区域到木偶版布局 [英] Dynamically add regions to Marionette layout
问题描述
我有一个布局,但不能提前定义所有的区域,因为它们不知道。
所以稍后在一个ItemView被创建,我想使用视图的ID作为区域的名称在布局中创建一个新的区域,所以我可以这样说:
layout.dynamicRegionName。显示(newItemView);
但是这里有循环依赖。
-
我还没有呈现视图,所以我不能引用它的DOM元素来在布局的调用.addRegion()
-
我无法渲染它,正是因为我希望通过调用它来通过动态添加的区域附加到DOM树。 show()
@DerickBailey在github中的Marionette.Layout文档中我相信在示例中有一个错误有: layout.show(new MenuView());
但从技术上讲,这接近于我们需要在这里,即能够做到:
layout.addRegion(VAR_WITH_NEW_REGION_NAME,aViewInstance);
并将其添加到其中的布局渲染直接在视图实例中。 >
我是否缺少一些其他明显的方法来实现?这是一个已知的缺失功能吗?有没有理由没有吗?
我知道这个以前的问题:动态地向布局添加/删除区域
但没有看到任何明确/明确的答案。
Marionette v1.0(v1.0.2是最新的,现在)支持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());
I have a layout, but cannot define all of its regions in advance because they are not known.
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.
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()
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 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?
I'm aware of this previous Q: "Dynamically add/remove regions to a layout" but don't see any clear/definite answer to it.
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屋!