我是流星和mongo db的新手。我正在使用[email protected]提出申请。我正在创建一个名为'/imports/api/collections/recipe.js'的文件。在这里我创建一个集合并将这个文件导入到'/server/main.js'和'/client/main.js'中。在recipe.js中,我只发布食谱集合,然后在我订阅的客户端文件中。直到这一点,一切都是正确的。然后我使用autoform创建一个表单,该表单运行良好并被创建。但这种形式永远不会发布。流星收集没有被自动创建在开始和autoform不张贴到mongo分贝
首先,我的假设是,当服务器启动时,那时我的数据库应该已经创建了一个名为recipe的集合,但事实并非如此。
其次,为什么autoform不工作?我认为这是因为第一个原因。
在客户端,我通过蒙古(流星玩具)看到我的食谱集合。
我的食谱文件 - '/imports/api/collections/recipe.js':
import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import { SimpleSchema } from 'meteor/aldeed:simple-schema';
var RecipesCollection = new Mongo.Collection('recipes');
RecipesCollection.allow({
insert(userId, doc){
return !!userId;
}
})
var RecipeSchema = new SimpleSchema({
name: {
type: String,
label: "Name"
},
desc: {
type: String,
label: "Description"
},
author: {
type: String,
label: "Author",
autoValue(){
return this.userId
},
autoform:{
type: "hidden"
}
},
createdAt: {
type: Date,
label: "Created At",
autoValue(){
return new Date();
},
autoform:{
type: "hidden"
}
}
});
RecipesCollection.attachSchema(RecipeSchema);
if (Meteor.isServer) {
// This code only runs on the server
Meteor.publish('recipes', function tasksPublication() {
return RecipesCollection.find({author: this.userId});
});
}
export const Recipes = RecipesCollection;
我的服务器的文件: '/server/main.js':
import { Meteor } from 'meteor/meteor';
import '/imports/startup/server/start.js';
import '/imports/api/collections/recipe.js';
我的客户js文件:
import { Template } from 'meteor/templating';
import { Recipes } from '/imports/api/collections/recipe.js';
import '/imports/ui/pages/NewRecipe.html';
Template.NewRecipe.onCreated(function bodyOnCreated() {
Meteor.subscribe('recipes');
})
Template.NewRecipe.helpers({
recipesCollection() {
return Recipes;
}
});
新配方模板:
<template name="NewRecipe">
<div class="new-recipe-container">
{{> quickForm collection=recipesCollection id="insertRecipeForm" type="insert" class="new-recipe-form" }}
</div>
</template>
我正在使用包:Collection2和autoform。任何帮助或建议,将不胜感激。谢谢
请随时通过分流我的流星学项目来使其工作。会非常大胆。 - https://github.com/devin6391/meteorLearn1/tree/master/recipebook
我不重新导入流星/流星。它根据es6模块系统的不同文件而不同。 此外,我不能直接使用RecipesCollection作为模块的变量而不是窗口或模板的变量 –
- 已完成。虽然你对多个流星/流星进口是正确的。我修正了这一点。 RecipesCollection集合不能直接放入quickform中,因为它不在窗口范围内。 –