gpt4 book ai didi

javascript - meteor 未捕获类型错误 : Cannot read property 'helpers' of undefined

转载 作者:行者123 更新时间:2023-12-01 03:03:17 25 4
gpt4 key购买 nike

我很好地遵循了meteor.com的指示,但我得到了这个错误。我也尝试将其更改为 template.registerhelper 但似乎没有输出响应。

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>

最佳答案

有问题的行是 Template.main.helpers正如错误消息所暗示的那样。

发生这种情况是因为您没有main模板。要么使用您想要的 html 创建一个,它应该位于 <Template> 内标签:

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

或者您可以将目标模板更改为 Template.body因为你正在使用的助手目前位于你的体内。

相关教程部分:

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.

关于javascript - meteor 未捕获类型错误 : Cannot read property 'helpers' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46337092/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com