Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/449.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父视图是否冒泡?_Javascript_Backbone.js_Marionette - Fatal编程技术网

Javascript 主干线木偶网.js父视图是否冒泡?

Javascript 主干线木偶网.js父视图是否冒泡?,javascript,backbone.js,marionette,Javascript,Backbone.js,Marionette,我引用了这个,我知道如何冒泡 但在我的情况下,我想冷静下来 就像我在父视图上单击一个按钮,然后触发所有子视图的一些函数一样 var parent = Marionette.CompositeView.extend({ triggers: { 'click #edit': "??" // trigger the childview } }) 以上只是描述我的概念的代码 编辑 或者也许不用木偶,可以用脊梁做把戏吗 有人知道怎么做吗 谢谢如果您使用的是木偶,那么您可

我引用了这个,我知道如何冒泡

但在我的情况下,我想冷静下来

就像我在父视图上单击一个按钮,然后触发所有子视图的一些函数一样

var parent = Marionette.CompositeView.extend({
    triggers: {
        'click #edit': "??"  // trigger the childview
    }
})
以上只是描述我的概念的代码

编辑

或者也许不用木偶,可以用脊梁做把戏吗

有人知道怎么做吗


谢谢

如果您使用的是木偶,那么您可以使用
this.children
访问所有子视图。
children
属性委托一些下划线函数,如
invoke
,因此您可以调用
this.children.invoke
。类似的东西可能适合您的需要:

var ChildView = Marionette.ItemView.extend({
  template: _.template('child'),

  myChildFunction: function() {
    console.log('child view', this);
  }
});

var ParentView = Marionette.CompositeView.extend({
  template: _.template('<button id="edit">Edit</button><div class="children"></div>'),

  childView: ChildView,

  childViewContainer: '.children',

  events: {
    'click #edit': 'triggerChildren'
  },

  triggerChildren: function() {
    this.children.invoke('myChildFunction');
  }
});
var ChildView=marionete.ItemView.extend({
模板:u.template('child'),
myChildFunction:function(){
log('child view',this);
}
});
var ParentView=Marionette.CompositeView.extend({
模板:u.template('Edit'),
childView:childView,
childViewContainer:“.children”,
活动:{
“单击#编辑”:“triggerChildren”
},
triggerChildren:function(){
this.children.invoke('myChildFunction');
}
});