【发布时间】:2017-01-13 23:00:52
【问题描述】:
我很好奇最好的方法是在流星中创建一个按钮来复制一个数组对象。例如,如果我有:
"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
}
],
}
],
如果我想使用客户端按钮复制整个 TasksWithData 数组(这是一个子文档并且没有 _id)...我该怎么做?
这是我要调用的事件:
'click .duplicate': function(){
Meteor.call('duplicateItem', this._id);
}
这是模板结构:
检查/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(触发用户查看活动检查的 ReactiveVar 模式):
{{#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}}
【问题讨论】:
-
复制到哪里?到另一个 mongo 文件?到临时变量?到同一个 mongo 文档中的另一个键?
-
实际上,我真的很想将它作为一个新的相同对象添加到同一个数组中。客户希望能够复制先前设置的检查,这样他们就不必从头开始重新添加它们。所有这些检查确实需要像上面一样存在于同一个数组中。
-
我也编辑了上面的代码。我的错。我忘了关闭父对象。
标签: javascript mongodb meteor