提问者:小点点

主干网/木偶网:为引导模式向动态添加的视图添加视图事件


我有一个木偶布局和演示目的的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将包含在内容区域中。

我有一个想法,现在创建一个单独的区域来显示情态动词。将事情更改为如下所示:

模板:

<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);
    }
});

这可以正常工作并渲染模态,但模态的事件会丢失,因为它们最初是由此设置的。BodyView。

模式有一个复选框,在change上运行此模式下的函数。BodyView,但我想为此绑定事件。从这个角度来看。BodyView。

我怎样才能做到这一点?我试过做这个。ModalView的el与此相同。BodyView的,但这打破了东西。我也尝试过使用委托事件,但没有成功。


共2个答案

匿名用户

此屏幕广播完全符合您的要求:http://www.backbonerails.com/screencasts/building-dialogs-with-custom-regions

代码如下:https://github.com/brian-mann/sc01-dialogs

匿名用户

如果将HeaderView作为ItemView(或CollectionView/CompositeView)包含在其中,则可以通过传递参数来实例化它,如

new HeaderView({events:{
"click .x" : function(){} // your function in-line or reference
});

所以同样适用于ModalView。