我一直在研究Meteor应用程序,并希望通过Backbone的路由功能添加多页功能。但是,当我这样做时:
meteor add backbone
meteor add underscore
然后尝试在应用程序中创建一个简单的“hello World”,它会与消息崩溃:
ReferenceError: Backbone is not defined
at app/backbone.js:33:2
at run (/Users/timj/Documents/backbone/.meteor/local/build/server/server.js:142:63)
at Array.forEach (native)
at Function._.each._.forEach (/usr/local/meteor/lib/node_modules/underscore/underscore.js:79:11)
at run (/Users/timothyjaeger/Documents/backbone/.meteor/local/build/server/server.js:142:7)
Exited with code: 1
因为我已经将骨干添加到我的流星应用程序中,所以不确定我做错了什么! js看起来像这样:
骨干 - 测试 - app.js
if (Meteor.isClient) {
var AppView = Backbone.View.extend({
// el - stands for element. Every view has a element associate in with HTML content will be rendered.
el: '#container',
// It's the first function called when this view it's instantiated.
initialize: function(){
this.render();
},
// $el - it's a cached jQuery object (el), in which you can use jQuery functions to push content. Like the Hello World in this case.
render: function(){
this.$el.html("Hello World");
}
});
var appView = new AppView();
}
if (Meteor.isServer) {
Meteor.startup(function () {
Backbone.history.start({pushState: true});
// code to run on server at startup
});
}
答案 0 :(得分:0)
Backbone是一个客户端框架。只需从if (Meteor.isServer) {..}
中删除与骨干网相关的代码并将其放入if (Meteor.isClient) {..}
,您就需要将代码移至客户端。
如果使用客户端和服务器文件夹对代码进行分区,则无需使用if (Meteor.isServer) {..}
或if (Meteor.isClient) {..}
,只需将骨干相关代码放入客户端文件夹即可。
我认为todos应用程序使用骨干,如果没有看看如何在客户端使用它的这个问题:
How do I create dynamic URL's with Meteor?
此外还有一个名为meteor-router
的meteor程序包,它在页面之间路由也非常出色,这也可以更舒适地满足您的需求。您可以在以下网址找到更多信息: