【发布时间】:2014-10-31 14:29:53
【问题描述】:
有人可以解释为什么router.on("route:myTest", function(page) {}); 不起作用吗?
我的Backbone.Router如下:
var MyRouter = Backbone.Router.extend({
initialize: function(){
Backbone.history.start({ pushState:true, root:"/subdir/" });
},
routes: {
'' : 'start',
'base' : 'myTest',
'base/:name': 'myTest',
'base/:name/:skill': 'myTest',
'*default': 'defaultRoute'
},
start: function(){
alert('Chapter 5 route invoked');
},
defaultRoute: function(){
alert('Router does not handle this route');
},
myTest: function(name,book){
if(name !== undefined){
if(book !== undefined){
alert([name, 'is reading', book].join(' '));
}else{
alert('Saying hello to ' + name);
}
}else{
alert('Saying hello!');
}
}
});
这是我的html页面上的代码:
function showBook(name){
console.log('Show book ' + name);
router.navigate('book/' + name);
}
router.on("route:myTest", function(page) { showBook('TestBook'); });
【问题讨论】:
标签: javascript backbone.js backbone-events backbone-routing