Using the Backbone.js router to navigate through views modularized with require.js

前端 未结 8 926
别跟我提以往
别跟我提以往 2020-12-22 23:41

I am separating my views and router into separate files with require. I then have a main.js file that instantiates the router, and also renders my default view.

My r

8条回答
  •  伪装坚强ぢ
    2020-12-23 00:21

    I know this question is old, but I am wondering why haven't you use require.js in order to get the router:

    define(['./PathToRouter', ], function (router) {
        return Backbone.View.extend({
            template: Handlebars.compile($('#template').html()),
    
            events: {
                'click .edit': 'edit'
            },
    
            render: function () {
                //Create and insert the cover letter view
                $(this.el).html(this.template(this.model.toJSON()));
                $('#View').html(this.el);
    
                return this;
            },
    
            edit: function () {
                router.navigate('Edit/' + this.model.id, true);
            }
        });
    });
    

提交回复
热议问题