gpt4 book ai didi

javascript - 如何设置 Meteor Insert AutoForm 将数据插入集合?

转载 作者:行者123 更新时间:2023-11-27 23:37:32 30 4
gpt4 key购买 nike

我正在尝试创建一个带有自动表单的表单,当我单击提交时,它会将新行(数据行)插入到集合中。我在此页面上找到了我想要的一个很好的示例,但我无法仅使用他们提供的解释/代码来​​使其工作。

http://autoform.meteor.com/insertaf

Schemas = {};

Template.registerHelper("Schemas", Schemas);

Schemas.Person = new SimpleSchema({
firstName: {
type: String,
index: 1,
unique: true
},
lastName: {
type: String,
optional: true
},
age: {
type: Number,
optional: true
}
});

var Collections = {};

Template.registerHelper("Collections", Collections);

People = Collections.People = new Mongo.Collection("People");
People.attachSchema(Schemas.Person);

Meteor.publish(null, function () {
return People.find();
});

People.allow({
insert: function () {
return true;
},
remove: function () {
return true;
}
<小时/>
{{#autoForm id="afInsertDemo" type="insert" collection=Collections.People}}
<div class="form-group {{#if afFieldIsInvalid name='firstName'}}has-error{{/if}}">
<label class="control-label">{{afFieldLabelText name='firstName'}}</label>
{{> afFieldInput name='firstName'}}
{{#if afFieldIsInvalid name='firstName'}}
<span class="help-block">{{{afFieldMessage name='firstName'}}}</span>
{{/if}}
</div>
<div class="form-group {{#if afFieldIsInvalid name='lastName'}}has-error{{/if}}">
<label class="control-label">{{afFieldLabelText name='lastName'}}</label>
{{> afFieldInput name='lastName'}}
{{#if afFieldIsInvalid name='lastName'}}
<span class="help-block">{{{afFieldMessage name='lastName'}}}</span>
{{/if}}
</div>
<div class="form-group {{#if afFieldIsInvalid name='age'}}has-error{{/if}}">
<label class="control-label">{{afFieldLabelText name='age'}}</label>
{{> afFieldInput name='age'}}
{{#if afFieldIsInvalid name='age'}}
<span class="help-block">{{{afFieldMessage name='age'}}}</span>
{{/if}}
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">Add Person</button>
<button type="reset" class="btn btn-default">Reset Form</button>
</div>
{{/autoForm}}

我收到以下错误消息:

Template is not defined

最佳答案

在没有充分了解客户端、服务器端或两者上的定义的情况下开始使用简单的架构和自动表单可能是一个挑战。在您的情况下,您需要在客户端和服务器上都有架构和集合定义。服务器上的发布和收集访问规则以及客户端上的模板。

我创建了以下meteorpad项目来进行说明(注意“/client”、“/server”和“/common”前缀):

http://meteorpad.com/pad/Xue5BWFwcjyv4QvL2/AF%20Test

该项目有一个合理的结构可供遵循:

https://github.com/matteodem/meteor-boilerplate

关于javascript - 如何设置 Meteor Insert AutoForm 将数据插入集合?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34002325/

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