Note that there are some explanatory texts on larger screens.

plurals
  1. POBackbone Modules and modules Communication
    primarykey
    data
    text
    <pre><code>&lt;head&gt; &lt;title&gt;&lt;/title&gt; &lt;script src="javascript/vendor/jquery-1.6.4.min.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="javascript/vendor/underscore.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="javascript/vendor/backbone.js" type="text/javascript"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;script type="text/javascript" &gt; var MyApp = (function(_, Backbone){ var myApp = {}; var initializers = []; myApp.addInitializer = function(callback){ var initializer = { obj: this, callback: callback } initializers.push(initializer); }; myApp.initialize= function(){ _.each(initializers, function(initializer){ initializer.callback.call(initializer.obj); }); }; // the event aggregator myApp.vent = _.extend({}, Backbone.Events); // the other app initialization code ... return myApp; })(_, Backbone); var MyModule = (function(MyApp, Backbone){ var MyView = Backbone.View.extend({ initialize: function(){ MyApp.bind("some:event", this.someCallback, this); }, someCallback: function(){ alert("I'm Doing Stuff!!!"); } }); // ... other code, including MyApp.addInitializer })(MyApp, Backbone); var AnotherModule = (function (MyApp, Backbone) { var anotherModule = {}; anotherModule.SomeFunction = function () { MyApp.trigger("some:event"); //alert("Hello"); }; return anotherModule; })(MyApp, Backbone); // kick it all off and show the alert box //$(function(){ // MyApp.initialize(); // AnotherModule.SomeFunction(); //});​ $(function () { MyApp.initialize(); AnotherModule.SomeFunction(); }); &lt;/script&gt; &lt;/body&gt; </code></pre> <p>I am getting error on this line MyApp.trigger("some:event"); . I copied the code from following link</p> <p>URL: <a href="http://lostechies.com/derickbailey/2011/11/17/introduction-to-composite-javascript-apps/" rel="nofollow">http://lostechies.com/derickbailey/2011/11/17/introduction-to-composite-javascript-apps/</a></p> <p>Can you help me using modules two or more and each of them have multiple views. I need to communicate them using backbone as the above URL did.</p> <p>Thanks.</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