我在 Meteor ( https://github.com/aldeed/meteor-autoform ) 中使用了非常好的 Autoform 包。我的反应式表单工作得很好-但想要填充表单数据以允许根据用户在表中选择一行进行编辑。可以在这里找到非常简单的示例:
http://autoform.meteor.com/insertaf
实际上,我想用用户单击以进行编辑的“人员”行中的数据填充表单数据,但不确定如何执行此操作。任何有关如何执行此操作的示例将不胜感激。谢谢!
表格代码:
{{#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}}
流星Javascript
Schemas = {};
UI.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 = {};
UI.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;
}
});