如何更新流星中的autoform字段

时间:2016-01-15 19:46:11

标签: javascript meteor meteor-autoform

我是Meteor autoform的新手,我使用aldeed:autoform以表格格式创建表单并且我能够插入数据,但是我没有得到如何在点击时更新我的​​表行字段。请帮助我如何使用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> 

1 个答案:

答案 0 :(得分:0)

据我了解您的问题,您希望拥有一个模板,该模板允许您更新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;
        }
    });
}