Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/478.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript js-ItemView获取父区域引用_Javascript_Backbone.js_Marionette - Fatal编程技术网

Javascript js-ItemView获取父区域引用

Javascript 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

js
区域
有一个
关闭
事件,在该事件中,他们可以判断自己是否关闭了其中一个
区域
中的一个子视图

我遇到的问题是,如果子视图本身调用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,这是为我做的。谢谢