に表示するrouter.getに渡す:私は内部のコレクションを照会名(文字列)、電子メール(文字列)や予定(オブジェクト)クエリオブジェクトレコードの内側と私は三つのフィールドがあるコレクション持つテーブル
を私は予定フィールド内これらのフィールドにアクセスし、ヘクタールを使用してテーブルの上にそれらを表示したい
{ __v: 0,
name: 'dan',
email: '[email protected]',
appointments:
[ { _id: 58373466542d6ae430a13337,
position: '1',
name: 'dan',
email: '[email protected]',
serviced: false,
hospital: 'Toronto hospital',
date: 'Thursday, November 24, 2016',
__v: 0 },
{ _id: 5837346a542d6ae430a13339,
position: '2',
name: 'dan',
email: '[email protected]',
serviced: false,
hospital: 'Calgary hospital',
date: 'Thursday, November 24, 2016',
__v: 0 },
]
:上記のクエリから
router.get('/appointments', ensureAuthenticated, function(req, res, next) {
var query = {email: req.user.email};
PatientList.find(query, function(err, data){
if (err) throw err;
res.render('appointments', {data : data, title: 'Appointments'});
});
});
データは、ユーザーの電子メールに基づいてrouter.getはこのようになりますndlebars。ハンドルと私のHTMLは、この
<table class="table table-striped table-bordered">
<thead>
<tr>
<td>Clinic</td>
<td>Appointment Date</td>
<td>Patient Number</td>
<td>Clinic Queue Status</td>
</tr>
</thead>
<tbody>
{{#each data}}
<tr>
<td>{{this.appointments.hospital}}</td>
<td>{{this.appointments.date}}</td>
<td>{{this.appointments.position}}</td>
<td>{{#if this.appointments.serviced}}
Please return to the clinic immediately.
{{else}}
Patient is currently being served.
{{/if}}
</td>
</tr>
{{/each}}
</tbody>
</table>
のように見えます。しかし、それは
まだ動作していない、まだ何も表示されていません。私が言及すべきは、別のコレクションを照会し、そのフィールドの中に保存することで、これらのオブジェクトを予定フィールドに追加することです。 QueuedUser.find({email:req.user.email}、function(err、list){ (err)throw err; PatientList({name:req.user.name、email:req.user.email、appointments:list}){(err)throw err; res.redirect( '/ users/appointments'); }); – user1836292