2015-01-02 34 views
0

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

感谢您的帮助。

回答

0

你做错了。

首先,您需要在体外​​声明模板标签。

其次,你需要正确地插入模板:{{>main}}

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

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

+0

谢谢!非常简洁的答案。 – Lee

相关问题