无法读取未定义的属性 'helpers' - 模板已命名
Cannot read property 'helpers' of undefined - template is named
In main.js Template.main 未定义,但我不明白为什么。这两个文件都在 /client 目录中。
我确定我遗漏了一些明显的东西。
main.html
<head>
<title>QuizAero</title>
</head>
<body>
<div class="container">
<header class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<a class="navbar-brand" href="/">QuizAero Admin Dashboard</a>
</div>
</header>
<template name="main">
{{#each categories}}
<div id="mainSection" class="col-lg-3 pull-left">
{{categories}}
</div>
{{/each}}
</template>
</div>
</body>
main.js
if (Meteor.isClient) {
var categoryNames = [
{
title: 'Air Law'
},
{
title: 'Meteorology'
},
{
title: 'Navigation'
}];
Template.main.helpers({
categories: categoryNames
});
}
if (Meteor.isServer) {
Meteor.startup(function () {
// code to run on server at startup
});
}
感谢您的帮助。
你做错了。
首先你需要在主体外声明你的模板标签。
其次,您需要正确插入模板:{{>main}}
第三,在each
中,数据上下文更改为正在迭代的项目,您可以访问属性 title
HTML: https://gist.github.com/mariorodriguespt/5215a98538b89b8af9ab
In main.js Template.main 未定义,但我不明白为什么。这两个文件都在 /client 目录中。
我确定我遗漏了一些明显的东西。
main.html
<head>
<title>QuizAero</title>
</head>
<body>
<div class="container">
<header class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<a class="navbar-brand" href="/">QuizAero Admin Dashboard</a>
</div>
</header>
<template name="main">
{{#each categories}}
<div id="mainSection" class="col-lg-3 pull-left">
{{categories}}
</div>
{{/each}}
</template>
</div>
</body>
main.js
if (Meteor.isClient) {
var categoryNames = [
{
title: 'Air Law'
},
{
title: 'Meteorology'
},
{
title: 'Navigation'
}];
Template.main.helpers({
categories: categoryNames
});
}
if (Meteor.isServer) {
Meteor.startup(function () {
// code to run on server at startup
});
}
感谢您的帮助。
你做错了。
首先你需要在主体外声明你的模板标签。
其次,您需要正确插入模板:{{>main}}
第三,在each
中,数据上下文更改为正在迭代的项目,您可以访问属性 title
HTML: https://gist.github.com/mariorodriguespt/5215a98538b89b8af9ab