【发布时间】:2013-10-10 22:47:04
【问题描述】:
我正在关注Organizing Backbone Using Modules tutorial,除了在撰写本文后我必须进行一些调整以适应对依赖项的更改之外,我无法让我的 .on() 事件触发当路由匹配时。
如果您查看索引路由器,您会看到一个警报和一个 console.log()。页面加载时也不会触发。也没有js错误。
任何帮助将不胜感激。
router.js
define([
'jquery',
'underscore',
'backbone',
'views/index',
'views/ideas'
], function($, _, Backbone, IndexView, IdeasView) {
var AppRouter = Backbone.Router.extend({
'': 'index',
'/ideas': 'showIdeas',
'*actions': 'defaultAction'
});
var initialize = function() {
console.log('this works so i know initialize() is being called');
var app_router = new AppRouter;
// not firing
app_router.on('route:index', function() {
alert('hi');
console.log('hi');
// var index_view = new IndexView();
// index_view.render();
});
// not firing
app_router.on('route:showIdeas', function() {
console.log('showIdeas');
var ideas_view = new IdeasView();
});
//not firing
app_router.on('route:defaultAction', function(actions) {
console.log('No route:', actions);
});
if (!Backbone.history.started ) {
Backbone.history.start();
console.log( "Route is " + Backbone.history.fragment );
}
};
return {
initialize: initialize
};
});
【问题讨论】:
-
什么是没有触发您的路由之一的 url 示例?
-
怎么样/或者更具体地说,0.0.0.0:3000