我在配置waitOn路由的一部分时遇到问题,其中一个订阅的参数由来自不同订阅的文档中的值确定.
游戏中的收藏品是候选人和访谈.面试将只有一名候选人.这是一些示例数据:
candidate = {
_id: 1
firstName: 'Some',
lastName: 'Developer'
//other props
};
interview = {
_id: 1,
candidateId: 1
//other props
};
Run Code Online (Sandbox Code Playgroud)
路由配置如下.
this.route('conductInterview', {
path: '/interviews/:_id/conduct', //:_id is the interviewId
waitOn: function () {
return [
Meteor.subscribe('allUsers'),
Meteor.subscribe('singleInterview', this.params._id),
// don't know the candidateId to lookup because it's stored
// in the interview doc
Meteor.subscribe('singleCandidate', ???),
Meteor.subscribe('questions'),
Meteor.subscribe('allUsers')
];
},
data: function () {
var interview = Interviews.findOne(this.params._id);
return {
interview: interview,
candidate: Candidates.findOne(interview.candidateId);
}; …Run Code Online (Sandbox Code Playgroud) 我有两个系列
并且我只想向已登录用户发布已分享给他的优惠.
实际上,我是通过使用辅助数组(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)