JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://underscorejs.org/underscore.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/backbone.js/1.0.0/backbone-min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/backbone.marionette/1.0.1-bundled/backbone.marionette.min.js"></script>
<header>
<h1>A Marionette Playground</h1>
</header>
<article id="main">
</article>
<script type="text/html" id="layout-template">
Layout Template
<div id="childRegion"</div>
</script>
<script type="text/html" id="child-template">
<button type="button" id="btn" >Click me :)</button>
</script>
JavaScript
// Define the app and a region to show content
// -------------------------------------------
var App = new Marionette.Application();
App.addRegions({
"mainRegion": "#main"
});
// Create a module to contain some functionality
// ---------------------------------------------
App.module("SampleModule", function(Mod, App, Backbone, Marionette, $, _){
// Define a view to show
// ---------------------
var MainView = Marionette.Layout.extend({
template: "#layout-template",
regions: {
childRegion: "#childRegion"
},
events: {
'click #btn': 'handleButtonClick'
},
/*triggers: {
"btn:clicked": function (args) {
// This is never triggered
alert('clicked caught in layout');
}
}*/
handleButtonClick: function() {
alert('btn clicked in child region and bubbled up to layout');
}
});
var ChildView = Marionette.ItemView.extend({
template: "#child-template" /*,
triggers: {
"click #btn": "btn:clicked"
},
onBtnClicked: function (args) {
alert('clicked caught in child view');
}*/
});
// Define a controller to run this module
// --------------------------------------
var Controller = Marionette.Controller.extend({
initialize: function(options){
this.region = options.region
},
show: function(){
var layout = new MainView({});
layout.on("show", function (args) {
var childView = new ChildView({});
layout.listenTo(childView, "btn:clicked", function (args) {
//alert('caught in layout like this though but not directly in the layout class');
});
layout.childRegion.show(childView);
});
...