无法呈现autoform模板

时间:2016-05-16 15:12:10

标签: meteor meteor-autoform

我有一个带集合的模式:

export const Cources = new Meteor.Collection('Cources');

Cources.schema = new SimpleSchema({
  courcePath: {
    type: String,
    label: 'Cource path'
  },
  courceTitle: {
    type: String,
    label: 'Cource title',
    max: 200
  },
  courceDescription: {
    type: String,
    label: 'Cource description'
  },
  lessonsNumber: {
    type: Number,
    label: 'Lessons number',
    min: 1
  },
  courceDuration: {
    type: String,
    label: 'Cource duration'
  }
});

Cources.attachSchema(Cources.schema);

模板:

<template name="AddCource_page">
  <div class="container">
    {{> quickForm collection="Cources" id="insertCourceForm" type="insert"}}
  </div>
</template>

但是,表单没有渲染,控制台中出现错误:Error: Cources is not in the window scope。当我添加助手时,同样的问题。我该如何解决?感谢。

2 个答案:

答案 0 :(得分:0)

我认为Cources.schema导致了这个问题。在这里,您可以像这样定义架构。

第一名:

架构部分:

export const Cources = new Meteor.Collection('Cources');

Cources = attachSchema(new SimpleSchema({
  courcePath: {
    type: String,
    label: 'Cource path'
  },
  courceTitle: {
    type: String,
    label: 'Cource title',
    max: 200
  },
  courceDescription: {
    type: String,
    label: 'Cource description'
  },
  lessonsNumber: {
    type: Number,
    label: 'Lessons number',
    min: 1
  },
  courceDuration: {
    type: String,
    label: 'Cource duration'
  }
})
);

第二名:

架构部分:     export const Cources;     Cources.Collection = new Meteor.Collection('Cources');

Cources.schema = new SimpleSchema({
  courcePath: {
    type: String,
    label: 'Cource path'
  },
  courceTitle: {
    type: String,
    label: 'Cource title',
    max: 200
  },
  courceDescription: {
    type: String,
    label: 'Cource description'
  },
  lessonsNumber: {
    type: Number,
    label: 'Lessons number',
    min: 1
  },
  courceDuration: {
    type: String,
    label: 'Cource duration'
  }
});

Cources.Collection(Cources.schema);

和模板部分

<template name="AddCource_page">
  <div class="container">
    {{> quickForm collection="Cources.Collection" id="insertCourceForm" type="insert"}}
  </div>
</template>

答案 1 :(得分:0)

除了更改以下语法之外,您无需执行任何操作:

Hello /e001/ world

您已使用 Cources.schema 而非 Schemas.Cources

相关问题