Javascript MeteorJS插入函数是';行不通

Javascript MeteorJS插入函数是';行不通,javascript,meteor,mongodb-query,Javascript,Meteor,Mongodb Query,我是meteor的新手,正在尝试制作一个简单的博客应用程序。但是我的插入函数似乎工作不正常。这是我的密码 这是我的模板 <template name="addpost"> <div class="container"> <h1> Add New Post</h1> <form class="new-post"> <label class="title"> Title:

我是meteor的新手,正在尝试制作一个简单的博客应用程序。但是我的插入函数似乎工作不正常。这是我的密码

这是我的模板

<template name="addpost">
  <div class="container">
    <h1> Add New Post</h1>
    <form class="new-post">
      <label class="title">
        Title:
        <input type="text" name="title" placeholder="Type to add new tasks" />
      </label>
      <label class="post-content">
        Write here:
        <input type="text" name="body" placeholder="Type to add new tasks" />
        <button class="add-post">Add Post</button>
      </label>

    </form>
  </div>
</template>
我没有删除自动发布和不安全的软件包。下面是mongoDB查询输出


默认情况下,当您提交表单时,它会发出另一个HTTP请求,该请求将重新加载页面并停止meteor正在执行的任何操作。要避免这种情况,您需要防止默认操作:

Template.addpost.events({
  submit: function(event) {
    event.preventDefault();
    // the rest of your code goes here
  }
});

除此之外,你的代码对我来说是正确的。您可以通过以下方式进行验证:
Posts.find().fetch()
在web控制台或通过
meteor shell

web控制台现在显示“调用方法'addPost'时出错:找不到方法[404]”在您发布问题后,可能会出现一些输入错误,因为它对我来说工作正常。如果您可以在github repo上重现问题或提供链接,我可以再看一看。
addPost
方法仅在客户端上定义。它需要位于共享目录(如
lib
)或
server
下。前者会给你的,明白了。谢谢你,大卫·韦尔登。
Template.addpost.events({
  submit: function(event) {
    event.preventDefault();
    // the rest of your code goes here
  }
});