-1

I have the next html page:

...
    <script src="/Scripts/App/pep.js"></script>

    </head>
    <body>
    <div id="main">
        &nbsp;
    </div>
    </body>
...

the 'pep.js' contains the next content:

var pep = {

    models: {
    },
    views: {

        loginView: Backbone.View.extend({

            tagName: 'div',

            id: 'loginContainer',

            el: $('#main'),

            events: {

            },

            initialize: function() {
                this.listenTo(this.model, "change", this.render);
            },

            render: function () {
                this.$el.html("<p>asd</p>");
                return this;
            }

        })

    },
    route: Backbone.Router.extend({

        routes: {
            "login": "login",    // #login
        },

        login: function () {
            var lv = new pep.views.loginView;
            lv.render();
        }

    }),
    onReady: function () {

        var r = new pep.route();
        Backbone.history.start();

        r.navigate('login');
    }
};

$(pep.onReady());

Routing has working, but the view isn't rendered. Is there an error? The Backbone.js version is 1.2.3 The Chrome does not display any errors. Debugging allowed us to see that the browser enters the router and executes the method. However, the method does nothing.

Cœur
  • 37,241
  • 25
  • 195
  • 267
HailToTheVictor
  • 388
  • 2
  • 8
  • 28
  • You seems to be listening to an undefined model `this.listenTo(this.model,`, are you sure it works as expected and doesn't throw any error ..? *"Debugging allowed us to see that the browser enters the router and executes the method"* - which method, to be exact..? *"However, the method does nothing"* - What is the expected behavior..? – T J Nov 02 '15 at 06:14

1 Answers1

0

This code works if dependent libraries positioned at the end of the body of the document, rather than in the header.

HailToTheVictor
  • 388
  • 2
  • 8
  • 28