S
S
semolex2014-04-19 14:37:54
backbone.js
semolex, 2014-04-19 14:37:54

Problem with connecting Require.js (Does not pull the template)

Hello!
There was a problem - require.js does not pull the template at the required url. (Uncaught TypeError: Cannot call method 'replace' of undefined )
When all the templates were in one file, and without require - everything worked.
Here is the dependency code.
routes.js:

r
define([
        "pages/RestaurantPage/views/LoginView",
    ],
    function(LoginView, AdminView, CookerView, WaiterView) {
        return Backbone.Router.extend({ 
        routes: {
                "": "index"              
            },
        index: function() {
                loginView = new LoginView;
                loginView.render();
            }
    });});

LoginView.js:
define([
        "underscore",
        "backbone",
        "jquery",
        "text!pages/RestaurantPage/templates/LoginTemplate.html"
    ],
    function(_, Backbone, $, LoginTemplate) {
        return Backbone.View.extend({
            
            el: '#content',
            render: function() {
                var that = this;
                var template = _.template($('#loginpage').html());
                that.$el.html(template);                
            }
        });
    }
);

Update:
After changing the code to this:
define([
        "underscore",
        "backbone",
        "jquery",

        "text!pages/RestaurantPage/templates/LoginTemplate.html"
    ],
    function(_, Backbone, $, LoginTemplate) {
        return Backbone.View.extend({
            template: _.template(LoginTemplate),
            el: '#content',
            render: function() {
                this.$el.html(this.template());
                return this;
             
            }
        });
    }

);

The error is gone....but nothing is rendered!
Jquery, Backbone, Underscore work

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Michael, 2014-04-19
@semolex

and if so?

return Backbone.View.extend({
            el: $('#content'),
            render: function() {
                this.$el.html(LoginTemplate);
            }
        });

M
Michael, 2014-04-19
@1099511627776

By the way, I'm doing the same code (requirejs + backbone) according to this tutorial:
backbonetutorials.com/organizing-backbone-using-modules
it worked the first time

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question