Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I tried to solve this in different ways but kept ending up with the following solution. The solution involves writing my code in modules and using marionette modules and vent to communicate with them. Marionette helped me a lot and I hope the different features further in my development.</p> <p>index.html</p> <pre><code>&lt;script type="text/javascript"&gt; $(function () { //var myModule = MyApp.module("MyModule"); // console.log(MyApp.MyModule.someData); //=&gt; public data MyApp.OrganizerModule.someFunction(); //=&gt; public data //var LayOutModel = new MyApp.ShellModule.LayOut(); var LayoutView = new MyApp.ShellModule.LayoutView(); LayoutView.render(); var Explorer = new MyApp.OrganizerModule.ExplorerView(); }); &lt;/script&gt; </code></pre> <p>The following templates are used:</p> <pre><code> &lt;script id="layout_temp" type="text/template"&gt; &lt;div id="layout"&gt; &lt;div id="header"&gt; header &lt;/div&gt; &lt;div id="container"&gt; &lt;div id="center" class="column"&gt; center &lt;/div&gt; &lt;div id="left" class="column"&gt; left &lt;/div&gt; &lt;div id="right" class="column"&gt; right &lt;/div&gt; &lt;/div&gt; &lt;div id="footer"&gt; footer &lt;/div&gt; &lt;/div&gt; &lt;/script&gt; &lt;script id="Explorer" type="text/template"&gt; &lt;div &gt; start : &lt;button&gt;Say hello&lt;/button&gt; &lt;/div&gt; &lt;/script&gt; </code></pre> <p>Here is the Module definition and the subscription of the event using Marionette</p> <pre><code>MyApp.module("ShellModule", function (ShellModule, MyApp, Backbone, Marionette, $, _) { ShellModule.LayoutView = Backbone.View.extend({ initialize: function () { //Backbone.ModelBinding.call(this); alert("Hello2"); MyApp.vent.on("toolClick_Event", function (cat) { alert("test toolClick_Event fired"); }); } // , events: { // 'toolClick_Event': 'toolClick_Event' // } , render: function () { var template = _.template($("#layout_temp").html(), {}); $("#Maincontainer").html(template); //$(this.el).append("&lt;ul&gt; &lt;li&gt;hello world&lt;/li&gt; &lt;/ul&gt;"); } }); }); </code></pre> <p>And the other Module that triggers the event using MyApp.vent.trigger.</p> <pre><code>MyApp.module("OrganizerModule", function (OrganizerModule, MyApp, Backbone, Marionette, $, _) { // Private Data And Functions // -------------------------- var myData = "this is private data"; var myFunction = function () { console.log(myData); } // Public Data And Functions // ------------------------- OrganizerModule.someData = "public data"; OrganizerModule.someFunction = function () { //console.log(MyModule.someData); alert(OrganizerModule.someData); } OrganizerModule.ExplorerView = Backbone.View.extend({ el: "#center", events: { 'click button': 'toolClick' } , initialize: function () { this.render(); this.setElement(this.el); } , render: function () { var template = _.template($("#Explorer").html(), {}); //this.$el.html.add(template); // $("#center").append(template); //return this.el; $(this.el).html(template); return this; } , toolClick: function () { alert("test toolClick"); // var template = _.template($("#Explorer").html(), {}); //$("#center").append(template); MyApp.vent.trigger('toolClick_Event'); $("#Maincontainer").append("&lt;div&gt; other data &lt;/div&gt;"); } }); }); </code></pre> <p>Hope this will be helpful to others.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload