【发布时间】:2015-03-31 16:46:19
【问题描述】:
我是 Meteor 的初学者,无法完成简单的任务,即遍历集合并将每个项目的单个属性打印到模板。我打开了自动发布,所以我没有编写发布/订阅功能。到目前为止我所做的所有其他组件都可以工作,所以我很确定问题出在下面的代码中。
在 HTML 中(注意注释)
<template name="tags">
<div class="tags">
{{#each printTags }}
{{name}} <br>
{{/each }}
<!-- why is nothing showing up here? -->
</div>
<template>
在JS文件中
if (Meteor.isClient) {
Tags = new Mongo.Collection("tags")
tags = Tags.find({}).fetch();
Template.tags.helpers({
printTags: tags
});
}
在客户端,在开发工具中
Tags.find().fetch().forEach(function(tag){console.log(tag["name"])})
1
2
3
4
5
【问题讨论】:
标签: meteor