【问题标题】:METEOR: Error invoking MethodMETEOR:错误调用方法
【发布时间】:2015-04-28 17:13:29
【问题描述】:

我有以下错误:

在服务器上找不到函数“saveCalEvent”

但我确实写了。

我为什么会得到:

调用方法“saveCalEvent”时出错:找不到方法 [404]

即使我确实编写了服务器端方法?

这是我的代码:

CalEvent = new Mongo.Collection('callevent');
if (Meteor.isClient) {
  Template.main.rendered = function(){
    var calendar = $('#calendar').fullCalendar({
      dayClick: function(date, allDay, jsEvent, view){
        var calendarEvent = {};
        calendarEvent.start = date;
        calendarEvent.end = date;
        calendarEvent.titel = 'New Event';
        calendarEvent.owner = Meteor.userId;
        Meteor.call('saveCalEvent', calendarEvent);
      }
    })
  }
}

if (Meteor.isServer) {
  Meteor.startup(function () {
    Meteor.methods({
      'saveCalEvent' : function(ce){
         CalEvent.insert(ce);
      }
    });
  });
}

【问题讨论】:

  • 我在控制台中发现 mongo 是未知的。控制台说:(出口,要求,模块,__filename,__dirname){ CalEvent = new Mongo.Coll | ^ ReferenceError: Mongo 未定义
  • 你是在最后一个版本的 Meteor 上,这个包代码还是经典(在clientserverlib...内)代码?
  • 文件系统:projekt/client/projekt.js
  • 啊,非常感谢。它不起作用导致它在客户端文件夹中。我将 projekt.js 放在 projekt 文件夹中,它可以工作
  • 我还有一个问题。我写了一个新主题,因为这里不可能写 n1 个文本。

标签: javascript meteor


【解决方案1】:

Meteor 以不同的方式处理某些目录。列出了特殊文件夹及其范围的列表here

存储在客户端文件夹中的服务器代码对服务器不可见,因此是死代码。

特殊目录有:

  • 客户
  • 客户端/兼容性
  • 服务器
  • 公开
  • 私人
  • 测试

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-21
    • 2015-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多