Meteor:插入失败:找不到方法

Ste*_*oss 25 coffeescript meteor

我收到insert failed: Method not found日志消息,它可能是这些线程中描述的结果:

但是,我没有看到如何.让我展示希望能够更清楚地解释的代码.我正在使用Coffeescript:

if Meteor.isClient
  @VINs = new Meteor.Collection("vins")

  scoped_vins = @VINs
  Template.vins.events =
    "click .icon-plus-sign": ->
      console.log "this is #{this}"
      realVIN = $("#your-vin").val().replace /\D/g, ''
      console.log "user id is: #{Meteor.userId()} vin is #{parseInt(realVIN)}"
      VINs.insert number: parseInt(realVIN), owner: Meteor.userId() if Meteor.userId()
      $("#your-vin").val('')
else
  @VINs = new Meteor.Collection("vins")
Run Code Online (Sandbox Code Playgroud)

我对Meteor完全是一个n00b,但我从上面提到的线程中收集的是该集合必须在客户端和服务器上可用.这不是我所做的,还是我发展咖啡失明?

谢谢!

Aks*_*hat 41

确保您还在服务器和客户端上声明了您的集合.

在上面@VINs = new Meteor.Collection("vins")的客户端和服务器代码中,你可能将代码放入/client目录中了吗?

如果是这样,这意味着代码将只在客户端上运行,即使您拥有elseif Meteor.isClient区块.

要解决此问题,请将您使用的行复制到目录中的.coffee文件中/server:

@VINs = new Meteor.Collection("vins")
Run Code Online (Sandbox Code Playgroud)