[英]How can I update autoform field in meteor
我是Meteor autoform的新手,我使用aldeed:autoform以表格格式創建表單,並且能夠插入數據,但是單擊時無法更新表行字段。 請幫我如何使用自動表格更新表格行字段
這是我的模板代碼:
Organisation = new Mongo.Collection("organisation"); var Schemas = {}; Schemas.Organisation = new SimpleSchema({ company: { type: String, label: "Company", max: 200, unique: true, autoValue: function () { if (this.isSet && typeof this.value === "string") { return this.value.toLowerCase(); } } }, best_telephone: { type: String, label: "Best Telephone", optional: true }, website: { type: String, label: "Website", optional: true }, email: { type: String, label: "Email", optional: true }, type_of_organisation: { type: String, label: "Type of Organisation ", optional: true, allowedValues: ['Our Company', 'Prospect', 'Customer', 'Supplier'] }, status_of_organisation: { type: String, label: "Status of Organisation", optional: true, allowedValues: ['Inactive', 'Active', 'Deleted'] }, author:{ type: String, label: "Author", autoValue: function(){ return this.userId }, autoform: { type:"hidden" } }, createdAt: { type: Date, label: "Created At", autoValue: function(){ return new Date() }, autoform: { type: "hidden" } }, }); Organisation.attachSchema(Schemas.Organisation); Template.organisation.helpers({ // Organisationss.isValid() items: function () { return Organisation.find({}, {sort: {name: 1}}).fetch(); }, });
<Template name="organisation"> <div class="container"> <table class="table table-bordered table-condensed"> <thead> <tr> <div class="form-inline"> {{> quickForm collection="Organisation" id="makeUniqueID" type="insert" doc=this autosave=false}} </div> </tr> </thead> </table> <table class="table table-bordered table-condensed"> <thead> <tr> <td style="width: 100px">Company</td> <td style="width: 100px">Best Telephone</td> <td style="width: 100px">Website</td> <td style="width: 100px">Email</td> <td style="width: 100px">Type of Organisation</td> <td style="width: 100px">Status of Organisation</td> </tr> </thead> <tbody> {{#each items}} <tr> <td class="open-modal company-name" value="Show modal">{{this.company}}</td> <td>{{this.best_telephone}}</td> <td>{{this.website}}</td> <td>{{this.email}}</td> <td>{{this.type_of_organisation}}</td> <td>{{this.status_of_organisation}}</td> </tr> {{/each}} </tbody> </table> </div> </Template>
據我了解您的問題,您希望有一個模板,該模板可讓您更新Organisation
集合中的多個文檔。 在這種情況下,您可以通過將AutoForm放在每個塊中來實現多個更新表單。
例如:
<template name="organisation">
<div class="container">
<table class="table table-bordered table-condensed">
<thead>
<tr>
<div class="form-inline">
{{> quickForm collection="Organisation" id="makeUniqueID" type="insert" doc=this autosave=false}}
</div>
</tr>
</thead>
</table>
<table class="table table-bordered table-condensed">
<thead>
<tr>
<td style="width: 100px">Company</td>
<td style="width: 100px">Best Telephone</td>
<td style="width: 100px">Website</td>
<td style="width: 100px">Email</td>
<td style="width: 100px">Type of Organisation</td>
<td style="width: 100px">Status of Organisation</td>
<td style="width: 100px">Action</td>
</tr>
</thead>
<tbody>
{{#each items}}
{{#autoForm collection="Organisation" id=updateFormName type="update" doc=this}}
<tr>
<td>{{> afFieldInput name='company'}}</td>
<td>{{> afFieldInput name='best_telephone'}}</td>
<td>{{> afFieldInput name='website'}}</td>
<td>{{> afFieldInput name='email'}}</td>
<td>{{> afFieldInput name='type_of_organisation' options=typesOfOrg}}</td>
<td>{{> afFieldInput name='status_of_organisation' options=statusOfOrg}}</td>
<td>
<button type="submit">Update</button>
</td>
</tr>
{{/autoForm}}
{{/each}}
</tbody>
</table>
</div>
</template>
if (Meteor.isClient) {
Template.organisation.helpers({
items: function () {
return Organisation.find({}, {sort: {name: 1}}).fetch();
},
typesOfOrg: function () {
return ['Our Company', 'Prospect', 'Customer', 'Supplier'].map((el) => ({label: el, value: el}));
},
statusOfOrg: function () {
return ['Inactive', 'Active', 'Deleted'].map((el) => ({label: el, value: el}));
},
updateFormName: function () {
return "updateOrgForm-" + this._id;
}
});
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.