Meteor Collection 2重复使用来自同一集合的数组项目进行AutoForm

时间:2017-01-12 03:35:03

标签: mongodb meteor meteor-autoform simple-schema meteor-collection2

我有一个带有几个数组的集合。我使用autoform来显示各种形式。

我需要将现有数据从同一个_id拉入另一个表单字段。

这是我的数据文件:



{
  "_id": "ERjvecg2GmSBktmn5",
  "clientName": "General Motors",
  "clientInfo": [
    {
      "fullname": "John Smith",
      "email": "jsmith@gmail.com",
      "phone": 2485551212,
      "phone2": 7345551212
    },
    {
      "fullname": "Billy Bob",
      "email": "bbob@gmail.com",
      "phone": 3135551212,
      "phone2": 7346661212
    }
  ],
  "facilityList": [
    {
      "name": "GM @ Ann Arbor",
      "id": "1234",
      "facilityType": "option1",
      "address": "12345 Main St Ann Arbor, MI 48888",
      "contacts": [
        {
          "contactName": "Jill Sutton",
          "contactEmail": "jsutton@gmail.com",
          "contactPhone1": 7348881212,
          "contactPhone2": 3132224444
        }
      ],
      "special": "gsgfsdgdsgdsgdgsdgsdgdgdgggdsgfdgdfgdgsdgsdg",
      "_id": "accde038-775d-4d11-b8fd-d0cc3b63c869"
    }
  ],
  "TasksWithData": [
    {
      "inspectionDetails": [
        {
          "inspector": "cHsSP6jadYa8wAeTi",
          "inspectorName": "Joe Reporter",
          "projectType": "inspection",
          "startDate": "2017-01-13T05:30:00.000Z",
          "desc": "fgfsdgsdgsdgdsgsdgdggsdgdg",
          "activeTask": false
        }
      ],
      "TaskItem": [
        {
          "DataFacilitySection": "dsfgsdfgds",
          "DataItemDescription": "item 1",
          "DataItemSection": "dfgdfgdf",
          "DataItemCode": "dfgdfgdf",
          "DataItemPass": null
        },
        {
          "DataFacilitySection": "ftydftuydrtuy",
          "DataItemDescription": "item 2",
          "DataItemSection": "dfgdgdf",
          "DataItemCode": "dfgdfgdf",
          "DataItemPass": null
        }
      ],
      "author": "Ss6TjGGzqWJRZYStx"
    }
  ]
}




我真正需要做的是获得" facilityList"对象在选择中显示为选项。

我已经设法用其他集合中的数据执行此操作:



  'TasksWithData.$.inspectionDetails.$.inspector': {
    type: String,
    label: "Inspector",
    optional: true,
    autoform: {
      firstOption: 'Choose an Inspector',
      options: function() {
        return Meteor.users.find({}, {
          sort: {
            profile: 1,
            firstName: 1
          }
        }).map( function ( c ){
          return{
            label: c.profile.firstName + " " + c.profile.lastName,
            value: c._id
          };
        } );
      }
    }
  },




但是当使用来自同一个_id的项目时,它似乎有点不同。

这是我的autoForm:



{{#autoForm collection="ClientData" id=UpdateForm type="update-pushArray" scope="TasksWithData" doc=this}}
{{> afQuickField name="inspectionDetails.0.TaskFacility"}}
{{> afQuickField name="inspectionDetails.0.inspector"}}
{{> afQuickField name="inspectionDetails.0.inspectorName"}}
{{> afQuickField name="inspectionDetails.0.projectType"}}
{{> afQuickField name="inspectionDetails.0.startDate"}}
{{> afQuickField name="inspectionDetails.0.desc"}}
<div class="panel panel-default">
  {{> afArrayField name="TaskItem"}}
</div>
<input class="btn btn-primary btn-block" type="submit" value="Add Task">
{{/autoForm}}
&#13;
&#13;
&#13;

我不确定是否可以在autoform端或架构上完成。以下是我用来尝试提取数据的模式示例:

&#13;
&#13;
  'TasksWithData.$.inspectionDetails.$.TaskFacility': {
    type: String,
    label: "Choose a Facility",
    optional: true,
    autoform: {
      firstOption: 'Choose a Facility',
      options: facilityList
  },
&#13;
&#13;
&#13;

显然是错的,但我真的很感激这方面的建议。

0 个答案:

没有答案