我在配置路由的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);
};
}
});
的問題是,我沒有candidateId傳遞給singleCandidate
認購的waitOn
方法,因爲它存儲在採訪文檔。
我想到了兩種可能的解決方案,但我並不十分喜歡他們中的任何一種。首先是將路線改爲/interviews/:_id/:candidateId/conduct
之類的路線。第二種是將數據非規範化並將候選人的信息存儲在訪談文檔中。
除了這兩個之外,還有其他的選擇可以實現嗎?
咄...很簡單。我看不到這片樹上的樹林。我在其他地方使用'singleCandidate'出版物,但我會添加一個'interviewCandidate'出版物。謝謝! –