【发布时间】:2019-06-06 23:09:23
【问题描述】:
我对流星相当陌生,我正在尝试使用#each 来迭代光标以填充表格。这是我的代码:
<template name="choral">
<div class="container" style="padding-top: 25px">
<div class="table-responsive">
<form id="orderForm">
<table class="table table-borderless table-dark">
<thead class="thead-light">
<tr>
<th>Title:</th>
<th>See the Music:</th>
<th>Hear the Music:</th>
<th>Format:</th>
<th>Price (per copy):</th>
<th>Quantity:</th>
</tr>
</thead>
<tbody>
{{#each piece in pieces}}
<tr>
<td id="name">{{piece.name}}</td>
<td id="pdf">PDF</td>
<td id="audio">AUDIO</td>
<td id="format">FORMAT</td>
<td id="price">{{piece.score}}</td>
<td id="qty"><input type ="number" name ="quantity" min="5"></td>
</tr>
{{/each}}
</tbody>
<tfoot>
<tr>
<td colspan="5"></td>
<td><button class="button" type ="submit">Add to Cart</button></td>
</tr>
</tfoot>
</table>
</form>
</div>
</div>
我的 js。
Template.choral.helpers({
pieces: function(){
return choralm.find({});
}
});
我在#each 标签之间输出一个空白行。我发布收集服务器端并订阅。我只是不知道在哪里看。有任何想法吗? 我的发布和订阅:
Meteor.publish('choralList', function() {
return choralm.find();
});
Template.choral.onCreated( function(){
Meteor.subscribe('choralList');
});
【问题讨论】:
-
。也许您的收藏是空的,或者您没有检查订阅是否准备就绪。能否请您显示您订阅的代码?
-
我进行了手动插入,所以我知道集合已填充。
-
'Template.choral.onCreated(function(){ Meteor.subscribe('choralList'); });'当我发表 i 'Meteor.publish('choralList', function() { return choralm.find(); });'