【发布时间】:2017-05-17 02:31:24
【问题描述】:
这应该是流星中简单的多对多关系,但我一定错过了一些东西,因为我无法让它工作。
我有一个名为 reblog 的集合,其中有一个名为 descovered 的整数数组,见图
我有第二个名为 posts 的集合,它是一个帖子集合,这些帖子有一个 ID。看第二张图
我想在 posts 和 reblog 集合之间创建多对多关系。即,我想匹配整数
descovered: 9
来自转发集合,带有:
id: 9
来自 posts 集合,这样我就可以只显示与 reblog 集合匹配的帖子。这当然可以让我显示帖子的标题和其他属性。
这是我的 js
Template.reblogging.helpers({
descovered() {
var id = FlowRouter.getParam('_id');
//fetch the reblog collection contents
var rebloged = reblog.find().fetch();
//log below is showing that the fetch is successful because i can see the objects fetched in console
console.log(rebloged);
//create the relationship between the posts collection and the reblog collection
var reblogger = posts.find({
id: {
$in: rebloged
}
}).fetch();
//nothing is showing with the log below, so something is going wrong with the line above?
console.log(reblogger);
return reblogger
}
});
我一定是遗漏了一些东西,因为这似乎是一件很简单的事情,但它并不工作
而我的 HTML 是这样的
<template name="reblogging">
{{#each descovered }}
<ul class="">
<li>
<h5 class="">{{title.rendered}}</h5>
</li>
</ul>
{{/each}}
</template>
【问题讨论】:
标签: javascript mongodb meteor meteor-collections