【发布时间】:2017-10-17 05:47:34
【问题描述】:
我正在使用带有 Meteor 的铁路由器(最新版本)。我有一个模板:
<template name="home">
{{#each products}}
<p>{{name}}</p>
{{/each}}
JJJJJJJJJJJJ
</template>
在lib/router.js:
Router.configure({
layoutTemplate:'layout'
});
Router.map(function () {
this.route('home', {
path:'/',
template:'home',
data : function () {
return Products.find();
}
});
});
当我运行该页面时,我看到带有此 JJJJJJJJJJJJ 的空白页面,添加用于测试以查看它是否加载了模板。
Products 集合中有 2 项带有 name。我可以通过 WEB 浏览器控制台读取(选择)、添加、删除该集合的项目,但该集合未在模板中呈现。
可能是什么错误?
【问题讨论】:
-
使用
data:设置模板的上下文,这意味着模板的this成为您的光标。所以Products.find()没有products字段。试试{{#each this}}。
标签: javascript meteor iron-router meteor-blaze