1

我有一个使用require js. 一切对我来说似乎都很好,但它不起作用。我router从我的电话app.js

路由器JS:

define([
   'jquery',
   'underscore',
   'backbone',
   'view/questions/index'
], function($, _, Backbone, IndexView){
var AppRouter = Backbone.Router.extend({
    routes: {
        '/': 'index'
    }
});

var initialize = function(){
    var app_router = new AppRouter();

    // Index Route
    app_router.on('index', function(){
        var indexView = new IndexView();
        console.log('test');
        indexView.initialize();
    });

    // Default Route
    app_router.on('defaultAction', function(actions){
        console.log('No Route', actions);
    });

    Backbone.history.start();
};

return {
    initialize: initialize
};
});

应用程序JS:

define([
  'jquery',
  'underscore',
  'backbone',
  'router'
], function($, _, Backbone, Router){
var initialize = function(){
    Router.initialize();
};

return {
    initialize: initialize
};
});
4

1 回答 1

5

伙计们,我实际上得到了这个工作。这是我在代码中所做的更改。

var AppRouter = Backbone.Router.extend({
    routes: {
        '': 'index'
    }
});

和这里:

app_router.on('route:index', function(){
    var indexView = new IndexView();
    console.log('test');
    indexView.initialize();
});
于 2013-01-19T02:41:36.380 回答