如何设置 Meteor Insert AutoForm 以将数据插入集合?

How to set up Meteor Insert AutoForm for inserting data into a collection?

我正在尝试创建一个带有自动表单的表单,当我单击提交时,它会向集合中插入一个新行(数据行)。我在这个页面上找到了一个很好的例子来说明我想要什么,但我无法让它只与他们提供的 explanation/code 一起工作。

http://autoform.meteor.com/insertaf

Schemas = {};

Template.registerHelper("Schemas", Schemas);

Schemas.Person = new SimpleSchema({
  firstName: {
    type: String,
    index: 1,
    unique: true
  },
  lastName: {
    type: String,
    optional: true
  },
  age: {
    type: Number,
    optional: true
  }
});

var Collections = {};

Template.registerHelper("Collections", Collections);

People = Collections.People = new Mongo.Collection("People");
People.attachSchema(Schemas.Person);

Meteor.publish(null, function () {
  return People.find();
});

People.allow({
  insert: function () {
    return true;
  },
  remove: function () {
    return true;
  }

{{#autoForm id="afInsertDemo" type="insert" collection=Collections.People}}
  <div class="form-group {{#if afFieldIsInvalid name='firstName'}}has-error{{/if}}">
    <label class="control-label">{{afFieldLabelText name='firstName'}}</label>
    {{> afFieldInput name='firstName'}}
    {{#if afFieldIsInvalid name='firstName'}}
    <span class="help-block">{{{afFieldMessage name='firstName'}}}</span>
    {{/if}}
  </div>
  <div class="form-group {{#if afFieldIsInvalid name='lastName'}}has-error{{/if}}">
    <label class="control-label">{{afFieldLabelText name='lastName'}}</label>
    {{> afFieldInput name='lastName'}}
    {{#if afFieldIsInvalid name='lastName'}}
    <span class="help-block">{{{afFieldMessage name='lastName'}}}</span>
    {{/if}}
  </div>
  <div class="form-group {{#if afFieldIsInvalid name='age'}}has-error{{/if}}">
    <label class="control-label">{{afFieldLabelText name='age'}}</label>
    {{> afFieldInput name='age'}}
    {{#if afFieldIsInvalid name='age'}}
    <span class="help-block">{{{afFieldMessage name='age'}}}</span>
    {{/if}}
  </div>
  <div class="form-group">
    <button type="submit" class="btn btn-primary">Add Person</button>
    <button type="reset" class="btn btn-default">Reset Form</button>
  </div>
{{/autoForm}}

我收到以下错误消息:

Template is not defined

在没有深入了解客户端、服务器端或两者的定义的情况下开始使用简单的模式和自动表单可能是一个挑战。在您的情况下,您需要在客户端和服务器上都有架构和集合定义。服务器上的发布和收集访问规则以及客户端上的模板。

我创建了以下 meteorpad 项目来说明(注意“/client”、“/server”和“/common”前缀):

http://meteorpad.com/pad/Xue5BWFwcjyv4QvL2/AF%20Test

本项目结构合理:

https://github.com/matteodem/meteor-boilerplate