[英]Marionette.js - ItemView get parent Region reference
Marionette.js Regions
有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...
});
},
});
如何使ItemView
与Layout通信,并告诉它自身已关闭(例如,通过单击ItemView
的退出按钮等)。 我需要Layout
来在ItemView
关闭时操纵其自身的附加DOM。
将侦听器附加到该区域的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
的关闭。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.