我正在按照教程 here 进行操作并且,在添加 html 和 JavaScript 来替换默认标记/代码后,我得到“Uncaught TypeError: Cannot read property 'helpers' of undefined”
这是我的 HTML,直接来自 tut:
<head>
<title>Todo List</title>
</head>
<body>
<div class="container">
<header>
<h1>Todo List</h1>
</header>
<ul>
{{#each tasks}}
{{> task}}
{{/each}}
</ul>
</div>
</body>
<template name="task">
<li>{{text}}</li>
</template>
...这是我的 JavaScript,也是直接来自 tut:
if (Meteor.isClient) {
// This code only runs on the client
Template.body.helpers({
tasks: [
{ text: "This is task 1" },
{ text: "This is task 2" },
{ text: "This is task 3" }
]
});
}
我在页面上看到的只是 h1(“待办事项列表”)。
出了什么问题,如何纠正?
最佳答案
抱歉,我没有仔细查看您的标记就回答了。请尝试以下操作:
<body>
<div class="container">
<header>
<h1>Todo List</h1>
</header>
{{> tasks}}
</div>
</body>
<template name="tasks">
<ul>
{{#each tasks}}
{{> task}}
{{/each}}
</ul>
</template>
<template name="task">
<li>{{text}}</li>
</template>
Template.tasks.helpers
而不是 Template.body.helpers
。
关于javascript - 为什么我在这个简单的 Meteor 应用程序中得到“"Uncaught TypeError: Cannot read property ' helpers' of undefined”?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32122584/