gpt4 book ai didi

javascript - 模板助手中的 Meteor quickForm 异常 : Error: Recipes is not in the window scope

转载 作者:太空宇宙 更新时间:2023-11-04 14:58:29 25 4
gpt4 key购买 nike

我无法让该应用程序在 Meteor 上运行。quickform 没有链接我的收藏。

“模板助手中的异常:错误:食谱不在窗口范围内”

这里有人可以帮忙吗?

这是我的快速表单代码

<template name="NewRecipe">
<div class="new-recipe-container">
{{> quickForm collection="Recipes" id="insertRecipeForm" type="insert" class="new-recipe-form" }}

</div>
</template>

这是我的集合模式

Recipes = new Mongo.Collection('recipes');

RecipeSchema = new SimpleSchema({
name: {
type: String,
label:"Name"
},
desc: {
type: String,
label:"Description"
},
author: {
type: String,
label:"Author",
autoValue: function() {
return this.userId
}
},
createdAt: {
type: Date,
label:"Created At",
autoValue: function() {
return new Date()
}
}

});

Recipes.attachSchema( RecipeSchema );

最佳答案

我无法对您的问题发表评论,因为我的声誉不到 50,所以我将其作为答案发布。

我正在关注相同的中级 meteor Level Up Tuts,但尝试关注 new Application structure and import syntax因为我使用的是 Meter 1.3,我想遵循最新的最佳实践。

我有这个错误是因为当我试图写

{{> quickForm collection="Recipes" id="insertRecipeForm" type="insert" class="new-recipe-form" }}

collection="Recipes" (with quotations)

这是一个问题,因为在 Meteor 1.3 中,由于 es2015 模块,Meteor 1.3 中不再有“全局”的东西。我没有像您那样定义 Collection(就像 Level Up Tuts 中的 Scott 那样),我使用 const 声明定义 Collection 并使用 ec2015 模块语法导出它(参见 github issue I提供)。重点是我的收藏不在全局范围中。所以我不得不编写一个模板助手来返回集合并像这样编写 quickForm 模板包含:

collection=Recipes (without quotations)

现在 Recipes 这是一个返回 Recipes 集合对象的模板助手

Template.NewRecipe.helpers({
Recipes(){
return Recipes;
}
});

我是从here了解到这个问题的

但是由于您使用的是较旧的 Meteor 应用程序结构方法(我想是吗?)Meteor 仍然支持它,所以我现在只能想到一个问题,即最新版本的 autoform 是专门为 Meteor 设计的1.3 牢记。我搜索了 Meteor 论坛,找到了一个 post那有同样的问题。

你可以尝试两件事:

  1. 尝试他为修复这些全局错误所做的工作,即将集合显式添加到窗口对象。
  2. 像他一样尝试恢复到旧版本的 autoform。

也许让我知道每个人的调查结果?

关于javascript - 模板助手中的 Meteor quickForm 异常 : Error: Recipes is not in the window scope,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37984295/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com