在我的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});
});
Backbone.history.start({pushState: true});
之前调用appRouter = new Aphorism;
,并将appRoute分配给全局变量,以查看它是否已初始化。 - wowpatrick