9

waitOnサブスクリプションのパラメーターの 1 つが、別のサブスクリプションからのドキュメントの値によって決定されるルートの部分を構成するのに問題があります。

プレイ中のコレクションは、候補者とインタビューです。面接では、候補者は 1 人だけです。サンプルデータは次のとおりです。

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問題は、メソッドでサブスクリプションに渡す候補 ID がないことですwaitOn。これは、インタビュー ドキュメントに保存されているためです。

考えられる解決策を 2 つ考えましたが、どちらもあまり好きではありません。1 つ目は、ルートを のように変更することです/interviews/:_id/:candidateId/conduct。2 つ目は、データを非正規化し、候補者の情報を面接ドキュメントに保存することです。

これら2つ以外に、これを達成するための他のオプションはありますか?

4

3 に答える 3

2

私はサブスクライブのコールバックを介してそれを解決することができた同様の問題を抱えていました

http://docs.meteor.com/#/basic/Meteor-subscribe

たとえば、都市 ID を持つユーザー データがあり、都市オブジェクトを取得する必要があるとします。

 waitOn: ->
    router = @
    [
        Meteor.subscribe("currentUserData", () ->
          user = Meteor.user()
          return unless user
          cityIds = user.cityIds
          router.wait( Meteor.subscribe("cities", cityIds)) if cityIds        
        )
    ]
于 2015-01-16T09:37:16.137 に答える
2

公開関数 singleCandidate を変更して、candidateId ではなく、interviewId をパラメーターとして受け取り、this.params._id を渡すことができます。

于 2014-02-17T22:15:01.763 に答える