简体   繁体   English

如何更新流星中的自动形成字段

[英]How can I update autoform field in meteor

I am new in Meteor autoform, I used aldeed:autoform to create form in tabular format and I'm able to insert the data, but I am not getting how can I update my table row field on click. 我是Meteor autoform的新手,我使用aldeed:autoform以表格格式创建表单,并且能够插入数据,但是单击时无法更新表行字段。 Please help me how can I update table row field with autoform 请帮我如何使用自动表格更新表格行字段

Here my template code:- 这是我的模板代码:

 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> 

As far as I understood your question, you want to have a single template which allows you to update several documents in your Organisation collection. 据我了解您的问题,您希望有一个模板,该模板可让您更新Organisation集合中的多个文档。 If this is the case, you could implement multiple update forms by placing your AutoForm within an each block. 在这种情况下,您可以通过将AutoForm放在每个块中来实现多个更新表单。

For example: 例如:

<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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM