插入 Meteor 集合时出错 [英] Getting a error inserting in to a Meteor Collection

查看:27
本文介绍了插入 Meteor 集合时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始使用 Meteor 并且遇到了第一个问题.我正在尝试将一个项目插入到我的收藏中.我收到以下控制台日志错误.有人可以帮助 Meteor 菜鸟吗?

I am starting to work with Meteor and I am running in to my first issue. I am trying to insert a item in to my collection. I get the below console log error. Can someone help a Meteor noob?

插入失败:找不到方法

这是导致错误的行:

Videos.insert({name: el.value});

我的js文件:

var Videos = new Meteor.Collection("videos");

if (Meteor.isClient) {
  Template.videoList.video = function() {
    return Videos.find();
  }

  Template.videoForm.events({
    'click button': function(e, t){
      var el = t.find("#name");
      Videos.insert({name: el.value});
      el.value = "";
    }
  });
}

推荐答案

当您尝试 Video.insert 时.Meteor 正试图同时在客户端和服务器上插入.Meteor 以这种方式设计它以帮助立即在客户端上反映更改(延迟补偿).

When you try Video.insert. Meteor is trying to insert both on the client and on the server as well. Meteor design it this way to help reflect the change instantly on the client(Latency Compensation).

当您的视频集合未在服务器上定义时(不在 Meteor.isServer 包装或服务器可以访问的文件中).它会抛出您遇到的错误.

When your Video collection is not defined on the server (not in Meteor.isServer wrap or file that can accessed by Server). It will throw the error you encountered.

如果您只想插入到客户端.您可以通过 _collection 访问它.所以你的插入语句将是 Videos._collection.insert(values);

If you want to insert to client only. You can access to it by _collection. So your insert statement would be Videos._collection.insert(values);

您可以在此屏幕截图中找到更多信息:http://www.eventedmind.com/feed/meteor-anatomy-of-a-collection-insert

You can find more info here in this screen cast: http://www.eventedmind.com/feed/meteor-anatomy-of-a-collection-insert

这篇关于插入 Meteor 集合时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆