您的位置:首页 > 其它

Backbone router 未生效可能情况

2015-09-02 00:00 363 查看
摘要: router

define(['backbone'],function(Backbone){
var navController = Backbone.Router.extend({
routes : {
'test':'test',
'nav/:path': 'gotoNav'
},
initialize:function(){//constructor
console.log(123);
},
test:function(){alert(1)},
gotoNav:function(path){
console.log(path);
}
});
return navController;
})

今天写一个backbone router, 结果发现routes没有生效, 由于长时间没用了

开始时候发现

情况1:

Backbone.history.start() 忘记调用了

情况2:

手贱,心血来潮把初始化方法写成 constructor 结果不生效,修改 initialize 后正常工作

constructor / initialize new Router([options])
When creating a new router, you may pass its routes hash directly as an option, if you choose. All options will also be passed to your initialize function, if defined.

我XX 我还以为这2个方法是同样效果的呢, 现在看来 initialize 应该是backbone constructor 的回调函数(猜测啊) 闲情可以看backbone源码

记录一下吧,省的以后又忘记了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  backbone router