Sub*_*ash 1 javascript jquery requirejs backbone.js
我有一个使用的骨干路由器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
};
});
Run Code Online (Sandbox Code Playgroud)
App JS:
define([
'jquery',
'underscore',
'backbone',
'router'
], function($, _, Backbone, Router){
var initialize = function(){
Router.initialize();
};
return {
initialize: initialize
};
});
Run Code Online (Sandbox Code Playgroud)
伙计们,我实际上有这个工作.这是我在代码中所做的更改.
var AppRouter = Backbone.Router.extend({
routes: {
'': 'index'
}
});
Run Code Online (Sandbox Code Playgroud)
和这里:
app_router.on('route:index', function(){
var indexView = new IndexView();
console.log('test');
indexView.initialize();
});
Run Code Online (Sandbox Code Playgroud)