简体   繁体   English

流星:将列表项从另一个集合中插入到一个集合中? 错误。 内部服务器错误

[英]Meteor: insert a list item into a collection from another collection onClick of a button? error. internal server error

I have a list of objects called categories, within them is an array of other objects which are the posts within that category, where id :129 is the category id and ID :100 is the posts id . 我有一个称为类别的对象列表,其中有一个其他对象的数组,这些对象是该类别内的帖子,其中id:129类别id,ID:100帖子id it looks like this 看起来像这样

在此处输入图片说明

In my html i have a button on each category item, that when clicked, it takes that category and its contents, (posts and other data) and inserts it into a new collection that is supposed to be specific to the user, like a bookmark. 在我的html中,我在每个类别项目上都有一个按钮,单击该按钮时,它将获取该类别及其内容(帖子和其他数据),并将其插入应该是特定于用户的新集合中,例如书签。 ie how tumblar, flipboard, google currents, zite have streams personal to the user, and when you follow a topic, the posts in that topic reflect on your personal stream. 即,风镜,翻板,谷歌潮流,zite如何对用户个性化流,并且当您关注某个主题时,该主题中的帖子会反映在您的个人流中。

However i'm getting two errors 但是我遇到两个错误

on the chrome console i get: 在chrome控制台上,我得到:

Error invoking Method 'addTimeline': Internal server error [500] 调用方法'addTimeline'时出错:内部服务器错误[500]

in my terminal i get: 在我的终端机上,我得到:

Exception while invoking method 'addTimeline' ReferenceError: doc is not defined 调用方法“ addTimeline” ReferenceError时发生异常:未定义doc

my server js is like this 我的服务器js是这样的

Meteor.methods({
    'addTimeline': function(data){
        Timeline.insert(doc);
    }
});

My client js looks like this 我的客户端js看起来像这样

Timeline.allow({
  insert: function (userId) {
     return (userId);
  }
 });
Template.CategoriesMain.events({
  'click .addFav':  function() {
    Meteor.call('addTimeline');

  }
});

My html looks like this 我的HTML看起来像这样

<template name="CategoriesMain">

<ul>
  {{#each articles}}
    <li>
      <a href="/catsingle/CategorySingle/{{_id}}"><h2>{{name}}</h2></a>
    </li>
    <button type="checked" name="button" class="addFav">add to fav</button>
  {{/each}}

truth is i'm quite new to meteor so i have been trying to hack and sash so i'm not sure what the problem is exactly or how to make it work. 事实是我对流星还很陌生,所以我一直在尝试破解和控制腰带,所以我不确定问题到底是什么或如何使其工作。

I can see two errors. 我可以看到两个错误。

Error 1 错误1

In your method addTimeline , you use the variable doc , but you name your parameter data . 在方法addTimeline ,使用变量doc ,但命名参数data

Error 2 错误2

In your click event handler, you call the method addTimeline , but you don't pass it any argument (the data parameter will be undefined . 在click事件处理程序中,调用方法addTimeline ,但不addTimeline传递任何参数( data参数将是undefined

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM