这种模式对于使用Marionette执行区域切换正确吗
Is this pattern correct for performing region switching with Marionette?
这个问题是基于我之前的一个问题在Marionette中从一个区域切换到另一个区域,视图没有正确呈现。它与之不同,因为我在问我所遵循的方法是否正确,或者是否存在另一种在区域之间进行切换的方法。
我创建了一个包含两个不同区域的布局。在initialize
上,布局在布局的两个区域中加载两个视图。说ViewA
和ViewB
。在ViewA
中触发一个事件。该事件由布局消耗以进行切换,并注入其他两个视图。说ViewC
和ViewD
。
这种方法正确吗?还是我必须遵循另一种模式?路由?
这里有一些代码,其中注释突出了重要部分。
onConfirm : function() {
this.leftView = new ViewC();
this.rightView = new ViewD();
this.leftRegion.show(this.leftView);
this.rightRegion.show(this.rightView);
},
initialize : function() {
// listen for event triggered from ViewA
// e.g. GloabalAggregator.vent.trigger("ga:confirm");
// where "ga:confirm" is a simple string
GloabalAggregator.vent.on("ga:confirm" , this.onConfirm, this);
this.leftView = new ViewA(), // creating here a new ViewC the style is applied correctly
this.rightView = new ViewB(); // creating here a new ViewD the style is applied correctly
},
onRender : function () {
this.leftRegion.show(this.leftView);
this.rightRegion.show(this.rightView);
}
要在Layout
中的视图之间切换,通常会使用控制器,请查看以下要点作为示例。
基本上,你将不得不创建一个新的控制器
var controller = Marionette.Controller.extend({
initialize: function(options){
this.leftRegion = options.leftRegion;
this.rightRegion = options.rightRegion;
},
swap: function() {
// do the region swapping here
}
});
你可以从以下视图创建它:
var controller = new MyController({
leftRegion: this.leftRegion,
rightRegion: this.rightRegion
});
(其中this
引用视图),并让它在listenTo的帮助下侦听该事件。
你可能会发现《木偶》作者的几个有用的例子:
- 小提琴
- wiki文章
相关文章:
- 无法在通过jQuery的ajax加载的页面中执行javascript
- onkeyup无法动态创建多个文本区域
- JavaScript执行暂时挂起页面
- 如何在ReactJS JSX中执行嵌套的if-else语句
- 当js函数's已执行
- 哪个先执行
- 在使用Polymer'加载所有json文件后执行方法;s的核心ajax
- HTML表单提交时未执行外部函数
- FabricJs-限制主对象内添加对象的移动区域
- 在Safari执行javascript之前对其进行修改
- 如何在文本区域的焦点上执行一次代码
- 如何将执行输出显示到文本区域中
- 是否可以对在 JQuery 中键入的文本区域执行实时检测
- 如果我的文本区域为空,请使用jquery执行此操作
- 这种模式对于使用Marionette执行区域切换正确吗
- 当鼠标不在按钮区域时执行点击按钮
- Ckeditor插件-在文本区域的特定元素上执行javascript函数
- jQuery-检测特定像素区域的点击,然后执行功能
- 单击对象内部的区域时如何执行函数
- 在Chrome浏览器的文本区域执行鼠标的奇怪行为