我有两个收藏:
Contracts = new Mongo.Collection('contracts');
Reminders = new Mongo.Collection('reminders');
这些在数据库中的结构或多或少是这样的:
合同:
{
"id": "4432234",
"contract": "C-42432432",
"description": "Description of contract",
"counterpart": "Company name",
"status": "awarded"
},
etc.
提醒:
{
"name": "Contract expiring",
"type": "expiring",
"contract": "C-42432432",
"reminderDate": "2015-06-01",
"urgency": 3
},
etc.
这里的“合同”-名称是指合同集合中的“合同”-名称。我们可以将多个提醒连接到同一个合同。因此,我希望它们在两个不同的集合中。
要获取我使用的合同数据:
<template name="example">
{{#each contracts}}
{{description}}
{{/each}}
</template>
对应的js:
Template.example.helpers({
contracts: function() {
return Contracts.find();
}
});
这工作正常,在这种情况下的结果是Description of contract
。
但是如果我想显示reminder-collection并从Contract-collection中获取相应的数据怎么办?换句话说:我想循环提醒集合并获得相同的输出。
<template name="notworking">
{{#each reminder}}
{{description}}
<!-- Here I want the description from the Contract-collection -->
{{/each}}
</template>
对应的js:
Template.notworking.helpers({
reminder: function() {
//?
}
});