7

我有这个:

Template.laps_t.laps = function () {
  return Practices.findOne({name: Session.get('practice')});
};

我该怎么做才能迭代这个并将值放在段落中?我是说:

{{#each laps.lapList}}
  <p>WHAT DO I HAVE TO PUT HERE TO PRINT THE VALUES OF THE LIST????</p>
{{/each}}

我这样做对吗?我必须在该段中添加什么?

编辑:

谢谢贾斯汀凯斯,你的解决方案成功了

现在我还有一个问题。我不仅想打印lap.lapList,而且lap.lapTimeList(这是另一个类似的列表[1,2,3,4,5,...])在这样的表中打印:

{{#each laps.lapList}}
  <tr>
    <td>iterate over and print the current value of lapList (solved using {{this}})</td>
    <td>iterate over and print the current value of lapTimeList</td>
  </tr>
{{/each}}

laps是同时拥有lapList和的对象lapTimeList。所以,这个想法是打印圈数和相应的时间。有谁知道怎么做?

4

1 回答 1

31

Iflaps.lapList[1,2,3]then 形式的数组:

{{#each laps.lapList}}
  <p>{{.}}</p>
{{/each}}

{{.}}指当前对象/元素。如果它包含字典/哈希,例如[{elapsedTime:32.0, location: 'Chicago'}],那么您可以使用键名:

{{#each laps.lapList}}
  <p>Lap took {{elapsedTime}}</p>
{{/each}}
于 2013-01-07T05:14:31.600 回答