Does the magic of marionette.js create a parent view?
I refer to this question and the document I know how to bubble up.
But in my situation, I want to get down.
Just like I click a button on the parent view and then run some function for my entire child mode.
var parent = Marionette.CompositeView.extend({
triggers: {
'click #edit': "??" // trigger the childview
}
})
above is just the code to describe my concept.
Edit
Or maybe not using a puppet, can you use your spine to do the trick?
Does anyone know how to do this?
thank
source to share
If you are using Marionette, you can access all of your child's performances with this.children
. The property children
delegates to some underscore functions like invoke
so you can call this.children.invoke
. Something like this might work for your needs:
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');
}
});
source to share