【发布时间】:2014-03-17 08:38:11
【问题描述】:
我在配置路由的 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);
};
}
});
问题是我没有在waitOn 方法中传递给singleCandidate 订阅的candidateId,因为它存储在面试文档中。
我想到了两种可能的解决方案,但我不太喜欢其中任何一种。首先是将路由更改为/interviews/:_id/:candidateId/conduct 之类的东西。二是将数据去规范化,将候选人的信息存储在面试文档中。
除了这两个之外,还有其他选择吗?
【问题讨论】:
标签: meteor iron-router