我的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
});
}
当我尝试运行它时,我得到了&#34;未捕获的TypeError:无法读取属性&#39;助手&#39;未定义&#34;?
怎么可能?模板助手是Meteor的关键组件,其使用示例是我的。
我在使用和不使用单引号括起辅助名称(例如&#34; firstStep&#34;)时尝试过它;也就是说,我已经尝试过这两个:
firstStep: function() {
..而且:
'firstStep': function() {
......一边打电话就是这样:
{{#if firstStep}}
{{> firstStepTemplate}}
{{/if}}
那么为什么&#39;助手&#39;据说不可读?
答案 0 :(得分:4)
Blizzard 只有一个“z”: Blizard