2016-08-26 3 views
0

私は少し騒がしく、私の出版物を稼働させるのに少し問題があります。私のデータには、多数の患者がいて、1人の患者のデータを見たいと思っています。これは私が私の出版物を構造化している方法です。流行の出版物/定期購読は機能しません

Meteor.publish('patients.single', function (patientId) { 
    check(patientId, String); 
    return Patients.find({_id: patientId}); 
}); 

、これは私が加入している方法です。

Router.route('/patients/:_id', { 
    layoutTemplate: 'ApplicationLayout', 
    yieldRegions: { 
    'single_patient': {to: 'content'} 
    }, 
    subscriptions: function() { 
    return Meteor.subscribe('patients.single', this.params._id); 
    } 
}); 

私も無駄に実際のテンプレート経由で購読することを試みた:

Template.patient_details.onCreated(function() { 
    this.subscribe('patients.single', Session.get("currentPatient")); 
}); 

出版物は理論的には簡単ですが、私はそれらを正しく得ることができません。私はここで間違って何をしていますか?

答えて

0

サブスクリプションがサーバーからミニ・モンゴーにデータを取得するのに時間がかかりますので、サブスクリプションの準備が整うのを待ってからデータを使用してください。

Iron Routerを使用している場合、サブスクリプションではなくwaitOnを使用すると、サブスクリプションの準備が完了するまでルータが強制的に待機し、サブスクリプションデータの取得中にロードテンプレートがレンダリングされます。

Router.route('/patients/:_id', { 
    layoutTemplate: 'ApplicationLayout', 
    yieldRegions: { 
    'single_patient': {to: 'content'} 
    }, 
    waitOn: function() { 
    return Meteor.subscribe('patients.single', this.params._id); 
    } 
    data: function() { 
    return Patients.findOne({_id: this.params._id}); 
    }, 
}); 

dataプロパティを使用して、テンプレートinstance.dataでデータを使用することもできます。

0

これを試してみてください:

サーバー側のJs

Meteor.publish('patients.single', function (patientId) { 
    check(patientId, String); 
    return Patients.find({_id: patientId}); 
}); 

クライアントJSファイル

Template.patient_details.helpers({ 
    getData : function(){ 
     return Collection.find().getch(); 

}); 

でルータJSファイル

Router.route('/patients/:_id', { 
    layoutTemplate: 'ApplicationLayout', 
    yieldRegions: { 
    'single_patient': {to: 'content'} 
    }, 
    waitOn: function() { 
    return Meteor.subscribe('patients.single', this.params._id); 
    } 
}); 

{{getData}}を呼び出すことを忘れないでください。 〜でテンプレートhtmlファイル

+0

ありがとうございました。私はこれを試しましたが、どういうわけか、それは動作していません...私は理由がわかりません。私は同じコレクションの他の出版物を持っているからでしょうか? – wiredfordesign

+0

質問を編集してテンプレートファイルを追加することもできます。複数の出版物のためではありません。同じコレクションから複数のパブリケーションを作成できます。 – Ankit

関連する問題