Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Meteor 未捕获类型错误:对象#<;对象>;没有方法';出版';_Meteor - Fatal编程技术网

Meteor 未捕获类型错误:对象#<;对象>;没有方法';出版';

Meteor 未捕获类型错误:对象#<;对象>;没有方法';出版';,meteor,Meteor,我有一个控制台错误: Uncaught TypeError: Object #<Object> has no method 'publish' p、 在model.js中有这样一行: Votes = new Meteor.Collection("votes"); 在client/client.js中有 Meteor.subscribe("votes"); (它不会对客户发誓) 谢谢:)您的发布功能应该包含发布内容的实际功能 从文档中: 要将记录发布到客户端,请在服务器上使用调用

我有一个控制台错误:

Uncaught TypeError: Object #<Object> has no method 'publish'
p、 在model.js中有这样一行:

Votes = new Meteor.Collection("votes");
在client/client.js中有

Meteor.subscribe("votes");
(它不会对客户发誓)


谢谢:)

您的发布功能应该包含发布内容的实际功能

从文档中:

要将记录发布到客户端,请在服务器上使用调用Meteor.publish 两个参数:记录集的名称和发布函数 每次客户端订阅该名称时,该Meteor都会调用

因此,函数应该如下所示:

Meteor.publish("votes", function () {
  return Votes.find();
});

这可能是你遇到的问题,也可能不是,但这是我看到的第一个问题

有一段时间没有人问我这个问题了,但因为我刚刚遇到并解决了同样的问题

我怀疑你有你的
Meteor.publish(“投票”)调用在客户端和服务器之间共享的文件,这意味着它在两种上下文中都执行

Meteor
类的客户端表示不支持
publish
,只支持服务器

如果将此调用移动到仅服务器的文件中(例如在
/server
中)或服务器执行上下文中(如下所示),则错误应该消失

if (Meteor.isServer) {
    Meteor.publish("votes", {
        return Votes.find(); // or whatever you like
    });
}

修复程序为“meteor update:”

可能重复相同的错误消息,但看起来问题不同。@emgee,尽管错误仍然有效;D
if (Meteor.isServer) {
    Meteor.publish("votes", {
        return Votes.find(); // or whatever you like
    });
}