Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8166307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:49:07+00:00 2026-06-06T19:49:07+00:00

<head> <title></title> <script src=javascript/vendor/jquery-1.6.4.min.js type=text/javascript></script> <script src=javascript/vendor/underscore.js type=text/javascript></script> <script src=javascript/vendor/backbone.js type=text/javascript></script> </head> <body> <script

  • 0
<head>
    <title></title>

    <script src="javascript/vendor/jquery-1.6.4.min.js" type="text/javascript"></script>
    <script src="javascript/vendor/underscore.js" type="text/javascript"></script>
    <script src="javascript/vendor/backbone.js" type="text/javascript"></script>


</head>

<body>
<script type="text/javascript" >

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();

});


</script>



</body>

I am getting error on this line MyApp.trigger(“some:event”); . I copied the code from following link

URL: http://lostechies.com/derickbailey/2011/11/17/introduction-to-composite-javascript-apps/

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.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T19:49:09+00:00Added an answer on June 6, 2026 at 7:49 pm

    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.

    index.html

    <script type="text/javascript">
            $(function () {
    
                //var myModule = MyApp.module("MyModule");
    
               // console.log(MyApp.MyModule.someData); //=> public data
    
                MyApp.OrganizerModule.someFunction(); //=> public data
    
                //var LayOutModel = new MyApp.ShellModule.LayOut();
    
                var LayoutView = new MyApp.ShellModule.LayoutView();
                LayoutView.render();
    
                var Explorer = new MyApp.OrganizerModule.ExplorerView();
    
            });
    
        </script>
    

    The following templates are used:

     <script id="layout_temp" type="text/template">
            <div id="layout"> 
                  <div id="header">
                header
            </div>
            <div id="container">
                <div id="center" class="column">
                    center
                </div>
                <div id="left" class="column">
                    left
                </div>
                <div id="right" class="column">
                    right
                </div>
            </div>
            <div id="footer">
                footer
            </div>
        </div>
        </script>
        <script id="Explorer" type="text/template">
           <div > start : 
           <button>Say hello</button>
           </div>
        </script>
    

    Here is the Module definition and the subscription of the event using Marionette

    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("<ul> <li>hello world</li> </ul>");
         }
    
    
    
        });
    
    });
    

    And the other Module that triggers the event using MyApp.vent.trigger.

    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("<div> other data </div>");
        }
        });
    
    });
    

    Hope this will be helpful to others.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this html code <html> <head> <title>JQuery Problem 2</title> <script type=text/javascript src=jquery-1.4.min.js></script> <script
<HTML> <HEAD> <title>Login</title> <script type=text/javascript src=http://script.auction.co.kr/common/jquery.js></script> <script type=text/javascript> $(document).ready(function() { $(:input[name='txtPassword']).blur(function(e){ $(this).css(background-color,white); }); $(:input[name='txtPassword']).focus(function(e){
<html> <head> <title>Latency Tracking Demo</title> </head> <body> <script type=text/javascript src=http://www.google-analytics.com/ga.js></script> <script type=text/javascript src=http://www.example.com/scripts/time-tracker.js></script> <script
<html> <head> <title>Question</title> <script type="text/javascript" > function MouseOverHand(ID) { var Cursor='hand'; var ID=ID; if
See example: <!DOCTYPE html> <html> <head> <title>language</title> <script type=text/javascript src=http://www.google.com/jsapi> </script> </head> <body> <div
Sample code: <!DOCTYPE html> <html> <head> <title>test</title> <script language=javascript type=text/javascript> function init() { var
JSFiddle URL: http://jsfiddle.net/sFe45/ Code: <html> <head> <title>Foo</title> <script type=text/javascript> var target; var anchor; function
Here is my code <html> <head> <head> <title></title> <script type=text/javascript charset=utf-8 src=cordova-1.6.0.js></script> <script type=text/javascript>
Take a look at this html: <head> <title>Test page</title> <script type=text/javascript> function submitForm() {
Heres my simple html source <html> <head> <title> Dec2Bin </title> <script type=text/javascript> function app()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.