我正在尝试使用autoform创建一个表单,当我单击提交时,它会向集合中插入一个新行(数据行)。我已经在这个页面上找到了一个很好的例子,但是我不能让它只使用它们提供的解释/代码。
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}}
我收到以下错误消息:
未定义模板
答案 0 :(得分:1)
简单的架构和autoform入门,而不必深入了解客户端,服务器端或两者的定义,这可能是一个挑战。在您的情况下,您需要在客户端和服务器上都具有架构和集合定义。服务器上的发布和集合访问规则以及客户端上的模板。
我已经创建了以下meteorpad项目来说明(注意&#39; / client&#39;,&#39; / server&#39;和&#39; / common&#39;前缀):
http://meteorpad.com/pad/Xue5BWFwcjyv4QvL2/AF%20Test
该项目具有合理的结构: