【发布时间】:2014-04-02 20:21:01
【问题描述】:
我有一个木偶布局,出于演示目的,html 看起来像:
<header id="header-region" class="page-title"></header>
<section id="template-content" class="full-section">
<div id="error-messages" class="fade main-section"><!-- errors --></div>
<div id="content-region"> </div>
</section>
它的布局视图的区域是:
regions: {
header: "#header-region",
content: "#content-region"
}
到目前为止,我已经在页面模板 html 中包含任何给定页面的模态 html,该模板 html 将包含在 content 区域中。
我有一个想法,现在创建一个单独的区域以显示模态。 将内容更改为如下所示:
模板:
<section id="template-content" class="full-section">
<div id="error-messages" class="fade main-section"><!-- errors --></div>
<div id="content-region"> </div>
<div id="modal-region"></div>
</section>
以及地区:
regions: {
header: "#header-region",
content: "#content-region",
modal: "#modal-region"
}
所以我希望能够做这样的事情:
// Controller
define([], function(){
initialize: function(){},
showHeaderView: function(){
this.HeaderView = new HeaderView();
this.layout.header.show(this.HeaderView);
},
showContentView: function(){
// this.BodyView's template used to contain the modal html
this.BodyView = new BodyView();
this.layout.content.show(this.BodyView);
},
showModalView: function(){
this.ModalView = new ModalView();
this.layout.modal.show(this.ModalView);
}
});
这可以正常工作并正确呈现模态,但模态的事件会丢失,因为它们最初是由 this.BodyView 设置的。
模态框有一个复选框,在 change 上运行一个在 this.BodyView 上的函数,但我想从 this.BodyView 绑定 this.ModalView 的事件。
我怎样才能做到这一点?我尝试过使 this.ModalView 的 el 与 this.BodyView 的相同,但这会破坏事情。我也尝试过使用delegateEvents,但没有成功。
【问题讨论】:
标签: javascript jquery twitter-bootstrap backbone.js marionette