Why would I get, "Uncaught TypeError: Cannot read property 'helpers' of undefined"?
Why would I get, "Uncaught TypeError: Cannot read property 'helpers' of undefined"?
我在我的 Meteor 项目中得到了这个 html:
<head>
<title>The Dentist Hurt My Fillings</title>
</head>
<body>
<h2>Thirteen Ways of Looking at a Duckbilled Platypus</h2>
<br/>
<br/>
<div class="container">
{{> whizzardBlizzard}}
</div>
</body>
<template name="whizzardBlizzard">
<form>
{{#if firstStep}}
{{> firstStepTemplate}}
{{/if}}
{{#if secondStep}}
{{> secondStepTemplate}}
{{/if}}
{{#if thirdStep}}
{{> thirdStepTemplate}}
{{/if}}
<input type="submit" value="Submit" class="button">
</form>
</template>
<template name="firstStepTemplate">
<h2>Step 1</h2>
</template>
<template name="secondStepTemplate">
<h2>Step 2</h2>
</template>
<template name="thirdStepTemplate">
<h2>Step 3</h2>
</template>
...还有这个 Javascript:
if (Meteor.isClient) {
// stepNum starts at 1
Session.setDefault('stepNum', 1);
Template.whizzardBlizzard.events({
"submit form": function (event) {
//event.preventDefault();
// save the vals to a new document in a collection
Session.set('stepNum', Session.get('stepNum') + 1);
}
});
Template.whizzardBlizard.helpers({
'firstStep': function() {
return (Session.get('stepNum') == 1);
},
'secondStep': function() {
return (Session.get('stepNum') == 2)
},
'thirdStep': function() {
return (Session.get('stepNum') == 3)
}
// . . . etc.
});
}
if (Meteor.isServer) {
Meteor.startup(function () {
// code to run on server at startup
});
}
当我尝试 运行 时,我得到,"Uncaught TypeError: Cannot read property 'helpers' of undefined"?
怎么可能?模板助手是 Meteor 的一个关键组件,它的使用示例反映了我的。
我已经尝试过将帮助程序名称(例如 "firstStep")用单引号引起来和不引起来;也就是说,我都试过了:
firstStep: function() {
..还有这个:
'firstStep': function() {
...这样称呼它时:
{{#if firstStep}}
{{> firstStepTemplate}}
{{/if}}
那么为什么 'helpers' 据报道不可读?
Blizzard在你的助手中只有一个"z":Blizard
我在我的 Meteor 项目中得到了这个 html:
<head>
<title>The Dentist Hurt My Fillings</title>
</head>
<body>
<h2>Thirteen Ways of Looking at a Duckbilled Platypus</h2>
<br/>
<br/>
<div class="container">
{{> whizzardBlizzard}}
</div>
</body>
<template name="whizzardBlizzard">
<form>
{{#if firstStep}}
{{> firstStepTemplate}}
{{/if}}
{{#if secondStep}}
{{> secondStepTemplate}}
{{/if}}
{{#if thirdStep}}
{{> thirdStepTemplate}}
{{/if}}
<input type="submit" value="Submit" class="button">
</form>
</template>
<template name="firstStepTemplate">
<h2>Step 1</h2>
</template>
<template name="secondStepTemplate">
<h2>Step 2</h2>
</template>
<template name="thirdStepTemplate">
<h2>Step 3</h2>
</template>
...还有这个 Javascript:
if (Meteor.isClient) {
// stepNum starts at 1
Session.setDefault('stepNum', 1);
Template.whizzardBlizzard.events({
"submit form": function (event) {
//event.preventDefault();
// save the vals to a new document in a collection
Session.set('stepNum', Session.get('stepNum') + 1);
}
});
Template.whizzardBlizard.helpers({
'firstStep': function() {
return (Session.get('stepNum') == 1);
},
'secondStep': function() {
return (Session.get('stepNum') == 2)
},
'thirdStep': function() {
return (Session.get('stepNum') == 3)
}
// . . . etc.
});
}
if (Meteor.isServer) {
Meteor.startup(function () {
// code to run on server at startup
});
}
当我尝试 运行 时,我得到,"Uncaught TypeError: Cannot read property 'helpers' of undefined"?
怎么可能?模板助手是 Meteor 的一个关键组件,它的使用示例反映了我的。
我已经尝试过将帮助程序名称(例如 "firstStep")用单引号引起来和不引起来;也就是说,我都试过了:
firstStep: function() {
..还有这个:
'firstStep': function() {
...这样称呼它时:
{{#if firstStep}}
{{> firstStepTemplate}}
{{/if}}
那么为什么 'helpers' 据报道不可读?
Blizzard在你的助手中只有一个"z":Blizard