【问题标题】:Meteor Reference Eror:NotebookSchema not definedMeteor 参考错误:未定义笔记本架构
【发布时间】:2016-10-24 14:55:19
【问题描述】:

我正在尝试创建一个 mongodb 集合并尝试附加架构以生成自动表单
我正在为此目的使用以下两个插件

  1. aldeed:autoform
  2. aldedd:collection2

我的代码

Notebooks = new Mongo.Collection("notebooks");

NotebookSchema = new SimpleSchema({
    name:{
        type:String,
        label:'Notebook Name'
    },
    author:{
        type:String,
        label:'Author'
    }
});
Notebooks.attachSchema(NotebookSchema);

以上代码在collections文件夹内,文件名为Notebooks.js

我的应用程序结构屏幕截图

我的错误截图

如果您需要有关任何事情的更多信息,请随时询问。

【问题讨论】:

  • 你在使用 Meteor^1.3 吗?
  • @corvid 我正在使用meteor@1.1.15我从版本中找到了这个

标签: mongodb meteor meteor-blaze meteor-autoform


【解决方案1】:

您可以像这样在 1.3+ 中导出您的收藏。

import { Mongo } from 'meteor/mongo';
import { SimpleSchema } from 'meteor/aldeed:simple-schema';

export const Notebooks = new Mongo.Collection('notebooks');
export const NotebookSchema = new SimpleSchema({ /** ... */ });
Notebooks.attachSchema(NotebookSchema);

export default Notebooks;

然后,您可以导入它并将其作为帮助程序公开。

import { Template } from 'meteor/templating';
import Notebook from '/imports/collections/Notebook';

Template.whatever.helpers({
  collection() {
    return Notebook;
  }
});

最后,在你的模板中使用它:

{{>autoForm id="meow" collection=collection}}

【讨论】:

  • 我正在使用meteor@1.1.15
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多