【问题标题】:Can't render autoform template无法呈现自动生成模板
【发布时间】:2016-05-17 22:26:59
【问题描述】:

我有一个带有集合的架构:

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。当我添加助手时,同样的问题。我该如何解决?谢谢。

【问题讨论】:

  • 您的意思可能是Course 而不是Cource。无论如何,如果您删除export const,它是否有效?
  • 尝试删除Course.schema,改用coursesSchema

标签: meteor meteor-autoform


【解决方案1】:

我认为 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'
  }
})
);

第二个:

架构部分: 导出常量课程; 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>

【讨论】:

    【解决方案2】:

    除了更改以下语法之外,您无需做任何事情:

     Schemas.Cources = new SimpleSchema({});
     Cources.attachSchema(Schemas.Cources);
    

    您使用的是 Cources.schema 而不是 Schemas.Cources

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-02
      • 2016-09-18
      • 2021-09-30
      • 2015-11-14
      • 2016-05-18
      • 2012-06-05
      • 2015-03-20
      • 2012-12-04
      相关资源
      最近更新 更多