我在配置waitOn
路由部分时遇到问题,其中订阅的参数之一由来自不同订阅的文档中的值确定。
正在播放的集合是候选人和面试。面试将只有一个候选人。以下是一些示例数据:
candidate = {
_id: 1
firstName: 'Some',
lastName: 'Developer'
//other props
};
interview = {
_id: 1,
candidateId: 1
//other props
};
路由配置如下。
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);
};
}
});
问题是我没有singleCandidate
在方法中传递给订阅的 CandidateId,waitOn
因为它存储在面试文档中。
我想到了两种可能的解决方案,但我不太喜欢其中任何一种。首先是将路线更改为类似/interviews/:_id/:candidateId/conduct
. 第二个是对数据进行非规范化并将候选人的信息存储在面试文档中。
除了这两个之外,还有其他选择吗?