gpt4 book ai didi

javascript - meteor 在模板中迭代列表

转载 作者:IT老高 更新时间:2023-10-28 13:17:24 27 4
gpt4 key购买 nike

我有这个:

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}}

我这样做对吗?我必须在该段中输入什么?

编辑:

谢谢 Justin Case ,您的解决方案成功了。

现在我还有一个问题。我不仅要打印 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 是同时包含 lapListlapTimeList 的对象。所以,这个想法是打印圈数和相应的时间。有人知道怎么做吗?

最佳答案

如果laps.lapList[1,2,3]形式的数组,那么:

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

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

{{#each laps.lapList}}
<p>Lap took {{elapsedTime}}</p>
{{/each}}

关于javascript - meteor 在模板中迭代列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14189672/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com