Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 模拟调用'的效果时发生异常;向上投票;。TypeError:undefined不是函数_Javascript_Mongodb_Coffeescript_Meteor - Fatal编程技术网

Javascript 模拟调用'的效果时发生异常;向上投票;。TypeError:undefined不是函数

Javascript 模拟调用'的效果时发生异常;向上投票;。TypeError:undefined不是函数,javascript,mongodb,coffeescript,meteor,Javascript,Mongodb,Coffeescript,Meteor,正在尝试将“向上投票”添加到的特定课程中 正如您从图中看到的,方法被正确调用。但是,我认为更新方法(mongo)不被理解。这是我个人的源代码 My courses.coffee(mongo collection)//顺便说一句:无法在此处设置正确的缩进格式: class @Course extends Minimongoid @_collection: new Meteor.Collection('courses') ... Meteor.methods({ createCourse:

正在尝试将“向上投票”添加到的特定课程中

正如您从图中看到的,方法被正确调用。但是,我认为更新方法(mongo)不被理解。这是我个人的源代码

My courses.coffee(mongo collection)//顺便说一句:无法在此处设置正确的缩进格式:

class @Course extends Minimongoid
@_collection: new Meteor.Collection('courses') 
...
Meteor.methods({
  createCourse: ->
    userId = Meteor.userId()
    throw new Meteor.Error 403, 'Please login to create a course' unless userId
    title = 'New Course'
    course = Course.create {
    owner: userId, courseTitle: title, published: 0, upvoters: [], votes: 0, slug: slugify(title)
  }
  return course._id

  upvote: (courseId) ->
    course = Course.first({_id: courseId})
    console.log course

  #userId = Meteor.user()
    Course.update {
      _id: courseId,
      # upvoters: {$ne: user._id}
      # }, {
      # $addToSet: {upvoters: user._id}
      $inc: {votes: 1}
    } 
还有我的html

<template name="courseListItem">
  <div class="course-list-item">
    <a href="{{#if isMyCoursesPath}}{{pathFor 'courseUpdate'}}{{else}}{{pathFor 'courseShow'}}{{/if}}">
      <div class="course-img">
        {{#if courseOwner}}
        <div class="owner-options">
          <a href="{{pathFor 'courseUpdate'}}" class="btn btn-default" title="Edit Course"><i class="fa fa-edit"></i></a>
          <button class="btn btn-danger delete" title="Delete Course"><i class="fa fa-trash-o"></i></button>
        </div>
        {{/if}}
        <img class="img-resonsive" src="{{courseThumb}}">
      </div>
      <div class="well relative">
        <div class="course"><h4>{{maxChars courseTitle 40}} by {{owner}}</h4></div>
        <p class="course-list-item-preview-text">{{maxChars getText 65}}</p>
        <p class="course-list-item-preview-text-votes"><a href="#" class="btn btn-default btn-xs"><i class="upvote fa fa-thumbs-up"></i></a> <strong>{{votes}}</strong> Votes</p>
        <!-- <p class="course-list-item-preview-text">12 Votes</p> -->
        <div class="bottom">
          <p><i class="fa fa-tags" title="Tags"></i> {{maxChars getKeywords 28}}</p>
          <p><i class="fa fa-group" title="Age Group"></i> {{age}}</p>
        </div>
      </div>
    </a>
  </div>
</template>
也许这是特定于Coffeecode或MinimongoId的注册?如果您想在本地运行此功能,请使用mrt安装,而不更新软件包或meteor。此外,您需要测试向上投票,您需要快速创建课程(在“教学”部分下)

最好的, 阿米尔
注:我只是想让你知道:我在扩展别人的代码,对CoffeeScript没有太多经验。

问题一定出在方法中:upvote,在那里你调用了一个不存在的函数

即使该方法看起来不错,也要尝试取消注释任何东西,而不是简单的console.log“hi”。然后逐行删除取消注释


或者可能是您正在使用的minimongoid软件包版本没有更新。请尝试课程。_collection.update(…)。

请修复您的咖啡脚本中的缩进,这非常重要。添加代码,选择它,然后点击
{}
图标。
课程。第一个
应该是
课程。findOne
?@muistooshort:done@PeepeL-G:这在某种程度上被设置为等同于Course.findOne。这就是console.log工作的原因
'click .upvote': (evt) ->
    Etc.prevent(evt)
    Meteor.call 'upvote', this._id