【发布时间】:2016-06-11 21:52:17
【问题描述】:
在学习 Meteor 时,我在编写一段非常简单的代码时遇到了很多问题。请参阅 cmets,它们是问题。
server/main.js
import { Meteor } from 'meteor/meteor';
import { Post } from './schema'
// Why is this required to make Post available in Meteor.startup?
// Isn't there auto-loading?
Meteor.startup(() => {
console.log(Post)
// This works, but why isn't Post available to meteor shell?
});
server/schema.js
import { Post } from './models/post'
export { Post }
server/models/post.js
import { Class } from 'meteor/jagi:astronomy';
// Why can't this be imported elsewhere, like main.js?
const Posts = new Mongo.Collection('posts');
const Post = Class.create({
name: 'Post',
collection: Posts,
fields: {
title: { type: String },
userId: String,
publishedAt: Date
},
});
export { Post }
除了这些问题,我怎样才能将我的应用程序加载到流星外壳中? Post 在此处未定义,即使它已在 Meteor.startup 中定义。我尝试将.load 与绝对路径一起使用,但这会破坏我的应用程序的导入,它使用相对路径。
至于我对哪些错误感到困惑:
- 当我尝试在
Meteor.startup()中使用import时,我收到一个错误,指出关键字import未定义。我正在使用ecmascript包。 - 当我在使用
Class的同一文件中没有import { Class }时,我会收到未知关键字错误。 - 如果我在 main.js 中没有
import { Post },那么Post是未定义的。 - 无法将应用程序加载到 Meteor shell。
【问题讨论】:
标签: javascript meteor