简体   繁体   中英

Meteor Uncaught TypeError: Cannot read property 'helpers' of undefined

I have followed well the instruction of meteor.com but i got this error. i itry also to change it into template.registerhelper but it seems that no output response.

main.js:8 Uncaught TypeError: Cannot read property 'helpers' of undefined at main.js (main.js:8) at fileEvaluate (modules-runtime.js?hash=8587d188e038b75ecd27ed2469a52b269e38fb62:343) at require (modules-runtime.js?hash=8587d188e038b75ecd27ed2469a52b269e38fb62:238) at app.js?hash=08534f7c8c7b3f0963300e61b8d521d38ce05c92:90

 import { Template } from 'meteor/templating'; import { ReactiveVar } from 'meteor/reactive-var'; import './main.html'; PlayersList = new Mongo.Collection('players'); if(Meteor.isClient) { Template.main.helpers({ "player" : function(){ return PlayersList.find(); }, }); } if(Meteor.isServer) { Meteor.startup(function () { // code to run on server at startup }); } 

 <head> <title>leaderboard</title> </head> <body> {{> hello}} <ul> {{#each player}} <li>{{name}}: {{score}}</li> {{/each}} </ul> </body> <template name="hello"> <h1>LeaderBoard</h1> </template> 

The problematic line is Template.main.helpers as hinted by the error message.

This happens because you do not have a main template. Either create one with the html you want, it should be inside a <Template> tag:

<Template name="main">
<!-- HTML -->
</Template>

Or you can change the Template you are targeting to Template.body since the helper you are using is currently located in your body.

Relevant tutorial part:

Everything inside tags is compiled into Meteor templates, which can be included inside HTML with {{> templateName}} or referenced in your JavaScript with Template.templateName. Also, the body section can be referenced in your JavaScript with Template.body. Think of it as a special "parent" template, that can include the other child templates.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM