我遇到控制台错误:
Uncaught TypeError: Object #<Object> has no method 'publish'
我的 server/server.js 中有一行 (控制台说错误就在这里)
Meteor.publish("votes");
附:在 model.js 中有这一行:
Votes = new Meteor.Collection("votes");
在 client/client.js 中有
Meteor.subscribe("votes");
(它不会在客户端发誓)
谢谢:)
最佳答案
自从有人问这个问题以来已经有一段时间了,但是因为我刚刚遇到并发现了同样的问题......
我怀疑你有你的Meteor.publish("votes");
调用在客户端和服务器之间共享的文件,这意味着它在两个上下文中执行。
Meteor
的客户端表示类不支持publish
,仅服务器。
如果将此调用移动到仅服务器文件(例如 <project_name>/server
中)或服务器执行上下文中(如下所示),则错误应该消失。
if (Meteor.isServer) {
Meteor.publish("votes", {
return Votes.find(); // or whatever you like
});
}
关于meteor - 未捕获的类型错误 : Object #<Object> has no method 'publish' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20919517/