这是我当前的应用程序结构:
/client/client.js
/server/server.js
collection.js
有 HTML 和 CSS 文件,但这些与我的问题无关。在将我的应用程序拆分为当前结构之前,它运行得很好,但它是 one big JavaScript file 。我的 Meteor.publish 和 Meteor.subscribe 无法正常工作,而且我的帐户用户界面配置错误。
This user had a similar problem ,但我的集合是在 collection.js 中定义的
我的 client.js 文件夹包含 Meteor.isClient 中的所有代码,server.js 包含 Meteor.isServer 中的所有代码以及 Meteor.methods。
Collection.js 只是 Tweets = new Mongo.Collection("tweets");
。
为什么我的发布和订阅不起作用?我不知道是否相关,但帐户 ui 也配置错误。
最佳答案
根据 meteor 文档http://docs.meteor.com/#/full/structuringyourapp
在文件加载顺序部分
There are several load ordering rules. They are applied sequentially to all applicable files in the application, in the priority given below:
- HTML template files are always loaded before everything else
- Files beginning with main. are loaded last
- Files inside any lib/ directory are loaded next
- Files with deeper paths are loaded next
- Files are then loaded in alphabetical order of the entire path
你的 client.js 和 server.js 在 collection.js 之前加载,它们比 collection.js 深一级
试试这个:
将 collection.js 移动到 lib/collection.js 中,这样你的文件结构如下所示
/client/client.js
/server/server.js
/lib/collection.js
关于javascript - 分离客户端和服务器代码的文件夹后的发布/订阅,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32674893/