我有两个系列
并且我只想向已登录用户发布已分享给他的优惠.
实际上,我是通过使用辅助数组(visibleOffers)来实现的,我通过循环为每个ShareRelations填充,然后在Offers.find上使用此数组作为$ in选择器.
我想知道这可能是这样做的流星方式,还是我可以用更少和/或更漂亮的代码?
我发布优惠的实际代码如下:
Meteor.publish('offersShared', function () {
// check if the user is logged in
if (this.userId) {
// initialize helper array
var visibleOffers = [];
// initialize all shareRelations which the actual user is the receiver
var shareRelations = ShareRelations.find({receiverId: this.userId});
// check if such relations exist
if (shareRelations.count()) {
// loop trough all shareRelations and push the offerId to the array if the …
Run Code Online (Sandbox Code Playgroud)