2015-01-02 36 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

相關問題