所以我有以下主干路线:
Nightbird.Routers.Errors = Nightbird.Routers.Core.extend({
routes: {
'server_error': 'serverError',
},
initialize: function(){
console.log('dasddasd');
},
serverError: function() {
console.log('asdasdasd');
var serverErrorView = new Nightbird.Views.ServerError();
serverErrorView.render();
}
});
它确实进入了此类,因为initialize
调用了该函数,当该路由加载时,我看到:dasddasd
在控制台中,但是我看不到asdasdasd
该网址是 localhost:9000/#server_error
有人可以解释我做错了吗?我不确定我还想提供什么进一步的信息,因此请索取任何其他详细信息。
以下是该应用程序的注册方式:
window.Nightbird = {
Models: {},
Collections: {},
Views: {},
Routers: {},
blogId: 0,
initialize: function() {
if (window.Development === undefined && window.Production === undefined) {
throw 'Production class (Production.config.js) cannot be missing. App Cannot load.';
}
if (window.Development !== undefined) {
this.blogId = window.Development.BLOG_ID;
} else {
this.blogId = window.Production.BLOG_ID;
}
new Nightbird.Routers.Posts();
new Nightbird.Routers.Errors();
if (!Backbone.History.started) {
Backbone.history.start();
} else {
Backbone.history.stop();
Backbone.history.start();
}
}
}
此类扩展:
Nightbird.Routers.Core = Backbone.Router.extend({
serverError: function(){
Backbone.history.navigate("server_error", {trigger: true});
}
});
为什么这么简单的抽象,因为通过这种方式,任何问题的获取或发布,或者您所拥有的都可以将您重定向到服务器错误路由。
然后在我index.html
做:
<!DOCTYPE html>
<html>
<body>
<div id="manage">
</div>
</body>
<script src="js/compiled.js"></script>
<script>
Nightbird.initialize();
</script>
</html>
我猜这是您实例化Backbone Router的方式尝试创建从Backbone.Router继承的Backbone Router。
当您检查Backbone.History.started是否为true时,可能不是。因此它将转到else语句,并且此时Backbone.History.star()是未定义的。因此它永远不会启动骨干。
希望能帮助到你。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加