javascript - 分离客户端和服务器代码的文件夹后的发布/订阅

标签 javascript meteor

这是我当前的应用程序结构:

/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:

  1. HTML template files are always loaded before everything else
  2. Files beginning with main. are loaded last
  3. Files inside any lib/ directory are loaded next
  4. Files with deeper paths are loaded next
  5. 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/

相关文章:

meteor - 下一条路线不是从页面顶部打开(向下滚动)。为什么?

javascript - meteor .js : Reusing methods and functions in events and helpers

javascript - 如何断言 HTML 元素是 Playwright 中的有效链接?

javascript - 记住 Bootstrap 表中的页面大小

javascript - 如何用 jQuery 替换部分 HTML 标签?

asp.net - 如何动态显示控件(选择下拉选项后)

Meteor:无法发送电子邮件:SenderError:来自命令的邮件失败 - 501 语法错误

javascript - 如何在 meteor 准备好 DOM 后执行辅助函数

javascript - 来自客户端的 Meteor.userId - 更改显示用户电子邮件,行为正确吗?

node.js - 我已经安装了meteor - npm 在哪里?