Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I downloaded and inspected your code. Following could be the issues:</p> <ol> <li><p><code>require.js</code> only works with <code>AMDs</code>. Since backbone no longer supports <code>AMD</code>. You will need to use <code>AMD</code> enabled version of <code>Backbone</code>. You can get it <a href="https://github.com/amdjs/backbone" rel="nofollow">here</a></p></li> <li><p>TestView is the dependency in you Router. So it loads before the Router is loaded. </p></li> </ol> <p>You might want to improve the coding pattern. Here is my suggestion:</p> <p>App.js</p> <pre><code>define([ </code></pre> <p>'backbone', 'router', ], function(Backbone, MainRouter){ 'use strict';</p> <pre><code>var AppView = Backbone.View.extend({ initialize: function(){ App.router = new MainRouter(); Backbone.history.start(); } }); return AppView; }); </code></pre> <p>Router.js</p> <pre><code>define([ 'backbone', 'view/TestView' ], function(Backbone, TestView){ var Main = Backbone.Router.extend({ routes: { 'test': 'test' }, test: function(){ new TestView({ // pass model or collection to the view // model: new TestModel // remember to require }); } }); return Main; }); </code></pre> <p><strong>EDIT</strong> Listening to events:</p> <pre><code>// in main.js var window.Vent = {}; _.extend(window.Vent, Backbone.Events); // now in any view you can trigger a event $('something').on('click', function(){ window.Vent.trigger('somethinghappened', this); // this is reference to current object }); // now in other view you can do window.Vent.on('somethinghappened', this.run, this); // this in the end is the reference we passed when event was triggered run: function(obj){ //this function will run when the event is triggered // obj is the object who triggered the event } </code></pre> <p>PS: why do you want to use router in view?? I have built quite a few backbone apps. Never needed to do so. </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.
    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