- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有两个集合:
Contracts = new Mongo.Collection('contracts');
Reminders = new Mongo.Collection('reminders');
这些在数据库中的结构或多或少像这样:
契约(Contract):
{
"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.
这里的“合约”名称指的是合约集合中的“合约”名称。我们可以将多个提醒连接到同一个契约(Contract)。因此我希望它们出现在两个不同的集合中。
要获取我使用的契约(Contract)数据:
<template name="example">
{{#each contracts}}
{{description}}
{{/each}}
</template>
对应的js:
Template.example.helpers({
contracts: function() {
return Contracts.find();
}
});
这工作正常,此实例的结果是合约描述
。
但是如果我想显示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() {
//?
}
});
最佳答案
您可能最好使用 Contracts._id
来引用 Reminders
集合中的契约(Contract),这样如果契约(Contract)名称和说明在某个时刻发生更改,您就不会这样做。无需更新所有相关提醒。
契约(Contract):
{
"_id": "tPN5jopkzLDbGypBu",
"contract": "C-42432432",
"description": "Description of contract",
"counterpart": "Company name",
"status": "awarded"
},
提醒:
{
"name": "Contract expiring",
"type": "expiring",
"contractId": "tPN5jopkzLDbGypBu",
"reminderDate": "2015-06-01",
"urgency": 3
},
然后,如果您想列出提醒并显示相关的契约(Contract)信息,您可以:
HTML:
<template name="remindersList>
{{#each reminder}}
Date: {{reminderDate}} Urgency: {{urgency}}
{{#with relatedContract}}
Description: {{description}} Counterpart: {{counterpart}} Status: {{status}}
{{/with}}
{{/each}}
</template>
JS:
Template.remindersList.helpers({
reminder: function(){
return Reminders.find(); // or whatever query you need to run
},
relatedContract: function(){
return Contracts.findOne({_id: this.contractId}); // 'this' will be the Reminder document
}
});
或者 - 如果您想保留非规范化架构,则 latedContract
函数只需返回 Contracts.findOne({contract: this.contract})
关于 meteor 合集: how to connect to different collections referring to each other?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30854295/
我以前使用过像 Netbeans 和 eclipse 这样的 IDE。 我在 friend 的电脑上下载了“Visual Studio Express 2013 for windows desktop
我正在尝试弄清楚如何在 GBA 大小的 EZ Flash 3 合 1 卡中对 PSRAM 进行编程。基本上重复 GBA Exploader 和其他程序所做的事情。 如果我选择一个 block 并对其进
Filter1=re.findall(r'',PageSource) Filter2=re.findall(r'',PageSource) Filter3=re.findall(r'(.*?).*?'
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许在 Stack Overflow 上提出有关通用计算硬件和软件的问题。您可以编辑问题,使其成为
我是一名优秀的程序员,十分优秀!