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

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

问题描述

我开始与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时.流星正在尝试同时在客户端和服务器上插入.流星以这种方式进行设计,以帮助将更改立即反映在客户端上(延迟补偿).

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

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

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