I am curious what the best approach might be to create a button in meteor to duplicate an array object. As an example if I had:
"TasksWithData": [
{
"inspectionDetails": [
{
"name": "somename",
"inspector": "Ss6TjGGzqWJRZYStx",
"inspectorName": "name of inspector",
"projectType": "inspection",
"startDate": "2017-01-12T05:00:00.000Z",
"desc": "a description",
"activeTask": true
}
],
"TaskItem": [
{
"DataFacilitySection": "dsfgsdfgds",
"DataItemDescription": "item 2",
"DataItemSection": "dfgdfgdf",
"DataItemCode": "dfgdfgdf",
"DataItemPass": null
}
],
}
],
If I wanted to duplicate the entire TasksWithData Array (which is a sub-document and does not have an _id) with a client button...how would I do this?
Here is the event I am calling:
'click .duplicate': function(){
Meteor.call('duplicateItem', this._id);
}
and here is the template structure:
Inspections/AddInspectionsHome:
<template name="AddInspectionHome">
<div class="container single-list conatiner-padding">
<h1>Task Navigator</h1>
<hr>
<div class="panel panel-default">
<div class="panel-heading no-padding">
<span>Select a Client</span>
</div>
{{#each findClients}}
{{> SingleClientInspection}}
{{/each}}
</div>
</div>
<!--TODO: Need to add the ability to duplicate these inspections-->
</template>
Inspections/SingleClientAddInspection (the ReactiveVar Mode that triggers the users ability to see active inspections):
{{#if activeMode}}
<div class="panel panel-default col-lg-12">
<a href="#" class="active btn btn-primary">Close</a>
<div class="panel panel-default">
<div class="panel-heading">View Active Tasks</div>
<table class="table table-striped">
<thead>
<tr>
<th>Facility</th>
<th>Inspector</th>
<th>Type</th>
<th>Due Date</th>
</tr>
</thead>
<tbody>
{{#each TasksWithData}}
{{#each inspectionDetails}}
{{#if activeTask}}
<tr>
<td>{{TaskFacility}}</td>
<td>{{inspectorName}}</td>
<td>{{projectType}}</td>
<td>{{startDate}}</td>
<td><a href="#" class="duplicate btn btn-success">Copy</a></td>
</tr>
{{/if}}
{{/each}}
{{/each}}
</tbody>
</table>
</div>
</div>
{{/if}}