简体   繁体   中英

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 . 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. 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.

However i'm getting two errors

on the chrome console i get:

Error invoking Method 'addTimeline': Internal server error [500]

in my terminal i get:

Exception while invoking method 'addTimeline' ReferenceError: doc is not defined

my server js is like this

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

My client js looks like this

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

  }
});

My html looks like this

<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

In your method addTimeline , you use the variable doc , but you name your parameter data .

Error 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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