0

我有这样的骨干观点

define(['backbone','text!templates/settings.html'], function( Backbone, SettingsTemplate) {
var SettingsView = Backbone.View.extend({
    el:"#settings-screen",

    viewTemplate: _.template(SettingsTemplate),

    events: {
        "click button#save-settings":"save"
    },

    initialize: function() {

    },

    render: function() {
        $("#game-viewport").html(this.viewTemplate);
    },

    save: function(event) {
        console.log(event);
    }
});

return SettingsView;

});

这是通过我的路由器初始化的视图

define(['backbone','views/settings'], function(Backbone,SettingsView) {

    var Router = Backbone.Router.extend({

        routes: {
            "newgame":"showGameview",
            "settings":"showSettingsview"
        },

        switchView: function(view) {
            if(this.currentView)
                this.currentView.close()

            this.currentView = view;
            this.currentView.render();
        },

        showGameview: function() {

        },

        showSettingsview: function() {
            var view = new SettingsView;
            this.switchView(view);
        }
    });
    return Router;
});

这会启动应用程序

require.config({

    paths: {
        'backbone':'./libs/backbone',
        'underscore':'./libs/underscore-min',
        'text':'./plugins/text',
        'domReady':'./plugins/domReady'
    },
    shim:{
        'backbone': {
            deps: ['underscore'],
            exports: 'Backbone'
        }
    }
});

require(['domReady','views/start','routers/router'], function(domReady, StartView, Router) {
    domReady(function() {
        var view = new StartView;
        view.render();

        var router = new Router();
        Backbone.history.start();
    });
});

但是在视图被渲染后,事件不会触发。有什么问题?

4

0 回答 0