无法阅读财产'助手'未定义的 - 模板被命名

时间:2015-01-02 01:36:38

标签: javascript meteor

在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
  });
}

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

你做错了。

首先,你需要在身体外面声明模板标签。

其次,您需要使用以下内容正确插入模板:{{>main}}

第三,在each内,数据上下文更改为正在迭代的项目,您可以访问属性title

HTML:https://gist.github.com/mariorodriguespt/5215a98538b89b8af9ab