var app = new Marionette.Application();
app.addRegions({
"mainRegion": "#main"
});
app.module("SampleModule", function(Mod, App, Backbone, Marionette, $, _){
var MySubView = Marionette.ItemView.extend({
template: '#MySubView',
events: {
'click #button': 'sendClick'
},
triggers: {
'afterClick': 'afterClick'
},
initialize: function initialize(){
this.on('afterClick', this.afterClick);
},
sendClick: function(e) {
e.preventDefault();
console.log('Good... Use your ventful capabilities boy...');
//trigger some method in the parent...
this.trigger('processClick');
},
afterClick: function(who) {
console.log("I've been waiting for you... The circle is now complete. When I left you I was the but the sender, now I am the receiver...", who);
}
});
var MyView = Marionette.Layout.extend({
template: '#MyView',
views: {},
regions: {
myRegion: '#myRegion'
},
onShow: function onShow(){
this.views.mySubView = new MySubView({ model: this.model }).on('processClick', this.sendBackClick, this);
this.myRegion.show(this.views.mySubView);
},
sendBackClick: function(){
//do some stuff, then, let the child know you're done...
console.log('heh heh heh heh.... Goood, goooood! Your triggers have made you powerful. Now, fulfil your parents destiny and take the event at my side!!!');
//use trigger?
this.views.mySubView.trigger('afterClick', 'from trigger');
//call method directly?
this.views.mySubView.afterClick('called directly');
}
});
var Controller = Marionette.Controller.extend({
initialize: function(options){
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.