2

Marionette.jsRegions有一个close事件,他们可以在其中判断他们自己是否在其中一个Regions.

我遇到的问题是,close如果子视图自己调用 close 则不会触发此事件。

请参阅以下内容:

var SubView = Marionette.ItemView.extend({

  // suppose close is called from the region item itself...
  internalClose: function() {
    this.close();
  },
});

var Layout = Marionette.Layout.extend({

  template: '<div class="region1"></div>',

  regions: {
    region1: '.region1',
  },

  onRender: function() {

    this.region1.show(new SubView());
    // When the SubView calls its own close, 
    // region1 does not register a close event.

    this.region1.on('close', function() {
      // self destruct or something exciting...
    });
  },
});

如何让ItemViewLayout 与 Layout 进行通信,并告诉它它自己关闭了(例如通过点击退出按钮ItemView或其他东西)。我需要在关闭Layout时操作自己的附加 DOM 。ItemView

4

1 回答 1

3

将监听器附加到区域的show事件并监听当前视图的close事件:

var region = this.region1;

region.on('show', function() {
    region.currentView.on('close', function() {
        // this message will cause the layout to self destruct...
     });
     // NOTE: You won't have to clean up this event listener since calling 
     //       close on either the region or the view will do it for you.
});

您可能可以这样做来代替close在该区域上收听,因为这只是表示currentView.

于 2013-09-17T05:09:46.640 回答