Javascript js-ItemView获取父区域引用
jsJavascript js-ItemView获取父区域引用,javascript,backbone.js,marionette,Javascript,Backbone.js,Marionette,js区域有一个关闭事件,在该事件中,他们可以判断自己是否关闭了其中一个区域中的一个子视图 我遇到的问题是,如果子视图本身调用close,则不会触发此close事件 见下文: var SubView = Marionette.ItemView.extend({ // suppose close is called from the region item itself... internalClose: function() { this.close(); }, }); v
区域
有一个关闭
事件,在该事件中,他们可以判断自己是否关闭了其中一个区域
中的一个子视图
我遇到的问题是,如果子视图本身调用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...
});
},
});
var SubView=marionete.ItemView.extend({
//假设从区域项本身调用close。。。
内部关闭:函数(){
这个。关闭();
},
});
var Layout=木偶网.Layout.extend({
模板:“”,
区域:{
区域1:“.region1”,
},
onRender:function(){
this.region1.show(new SubView());
//当子视图调用自己的close时,
//region1未注册关闭事件。
this.region1.on('close',function()){
//自毁还是什么令人兴奋的事。。。
});
},
});
如何让
ItemView
与布局通信,并告诉布局它自己关闭了(例如通过点击ItemView
中的退出按钮或其他方式)。我需要布局
在项目视图
关闭时操作自己的添加DOM。将侦听器附加到区域的显示
事件,并侦听当前视图的关闭
事件:
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
我不知道currentView,这是为我做的。谢谢