【发布时间】:2013-01-26 21:58:06
【问题描述】:
在我的 Meteor 应用程序中,Backbone 路由器仅在用户登录时工作(通过 accounts-base 包)。真奇怪。该路由器本身工作正常。当用户未登录时,根本不会调用 showSaying()函数。
以下是客户端文件夹中client.js 中的代码。我需要对会话或自动发布做些什么吗?
AphorismView = Backbone.View.extend({
el: "#aphorism-item",
initialize: function(){
_.bindAll(this, "render");
this.render();
},
render: function() {
this.$el.append("<p style='height:600px; background-color:blue;'>hi</p>");
}
});
// Creates a route to view the selected aphorism
var Aphorism = Backbone.Router.extend({
routes: {
"saying/:id": "showSaying"
},
showSaying: function (id) {
var aphorism_view = new AphorismView();
alert('Saying id ' + id + '.');
}
});
//establishes the router
appRouter = new Aphorism;
//Sets up backbone
Meteor.startup(function () {
filepicker.setKey("AerIOvsmAQRGaNdEv0judz");
filepicker.constructWidget(document.getElementById('attachment'));
Backbone.history.start({pushState: true});
});
【问题讨论】:
-
我怀疑这与加载速度/顺序有关,并且登录后加载时间更长,导致 appRouter 准时准备就绪。尝试将 appRouter 声明放在 Meteor.startup 中。
-
试过这个 Rahul - 没用
-
我还没有开发过Win8 Metro Apps,所以我不知道是否有像浏览器一样的开发控制台。如果有,我会在
Backbone.history.start({pushState: true});之前调用appRouter = new Aphorism;并将appRoute 分配给一个全局变量以查看它是否已被初始化。
标签: javascript backbone.js meteor router