在 Meteor 中使用空格键逻辑不遵守逻辑
Using Spacebars logic in Meteor not obeying logic
我有一个模板助手,它 returns 会话的值,在本例中它以数字 1 返回:
Template.Student.helpers({
curWeek: function () {
return Session.get('CurrentWeek').substr(0, 1);
},
我的模板有一个 table,我试图根据辅助函数的值将它的一部分打印到 table。所以我在模板中有一些逻辑来打印正确的部分。但它不服从逻辑。即使 curWeek 的值 returns 值为 1,模板 运行 也是 {{#if curWeek 2}} 下的逻辑,因此两者都在 table 中。我只想要 {{#if curWeek 1}} 到 运行 下的部分,因为这就是值。我没有正确使用逻辑吗?
<template name="Student">
{{#modalizeBody}}
<table class="bordered narrow">
<thead>
<tr>
<th>Name</th>
<th>Shift</th>
<th>Age</th>
<th>Sex</th>
<th>Level</th>
<th>Sun</th>
<th>Mon</th>
<th>Tue</th>
<th>Wed</th>
<th>Thu</th>
<th>Fri</th>
<th>Sat</th>
</tr>
</thead>
<tbody>
{{#each StudsWk1Master}}
{{#if curWeek 1}}
<tr>
<td>{{FullName}}</td>
<td>{{RoomWk1}}</td>
<td>{{calculateAge Bdate}}</td>
<td>{{Sex}}</td>
<td>{{Level}}</td>
<td>{{formatName this.Teachers.Week1.Sunday}}</td>
<td>{{formatName this.Teachers.Week1.Monday}}</td>
<td>{{formatName this.Teachers.Week1.Tuesday}}</td>
<td>{{formatName this.Teachers.Week1.Wednesday}}</td>
<td>{{formatName this.Teachers.Week1.Thursday}}</td>
<td>{{formatName this.Teachers.Week1.Friday}}</td>
<td>{{formatName this.Teachers.Week1.Saturday}}</td>
</tr>
{{/if}}
{{/each}}
{{#each StudsWk1Master}}
{{#if curWeek 2}}
<tr>
<td>{{FullName}}</td>
<td>{{RoomWk2}}</td>
<td>{{calculateAge Bdate}}</td>
<td>{{Sex}}</td>
<td>{{Level}}</td>
<td>{{formatName this.Teachers.Week2.Sunday}}</td>
<td>{{formatName this.Teachers.Week2.Monday}}</td>
<td>{{formatName this.Teachers.Week2.Tuesday}}</td>
<td>{{formatName this.Teachers.Week2.Wednesday}}</td>
<td>{{formatName this.Teachers.Week2.Thursday}}</td>
<td>{{formatName this.Teachers.Week2.Friday}}</td>
<td>{{formatName this.Teachers.Week2.Saturday}}</td>
</tr>
{{/if}}
{{/each}}
</tbody>
</table>
{{/modalizeBody}}
</template>
您的助手未测试是否相等。你有:
{{#if curWeek 1}}
但是您的助手只是 return 当前一周,不需要参数。
只需将参数添加到您的辅助函数,然后 return 一个布尔值:
Template.Student.helpers({
curWeek: function (value) {
return Session.get('CurrentWeek').substr(0, 1) === value;
},
我有一个模板助手,它 returns 会话的值,在本例中它以数字 1 返回:
Template.Student.helpers({
curWeek: function () {
return Session.get('CurrentWeek').substr(0, 1);
},
我的模板有一个 table,我试图根据辅助函数的值将它的一部分打印到 table。所以我在模板中有一些逻辑来打印正确的部分。但它不服从逻辑。即使 curWeek 的值 returns 值为 1,模板 运行 也是 {{#if curWeek 2}} 下的逻辑,因此两者都在 table 中。我只想要 {{#if curWeek 1}} 到 运行 下的部分,因为这就是值。我没有正确使用逻辑吗?
<template name="Student">
{{#modalizeBody}}
<table class="bordered narrow">
<thead>
<tr>
<th>Name</th>
<th>Shift</th>
<th>Age</th>
<th>Sex</th>
<th>Level</th>
<th>Sun</th>
<th>Mon</th>
<th>Tue</th>
<th>Wed</th>
<th>Thu</th>
<th>Fri</th>
<th>Sat</th>
</tr>
</thead>
<tbody>
{{#each StudsWk1Master}}
{{#if curWeek 1}}
<tr>
<td>{{FullName}}</td>
<td>{{RoomWk1}}</td>
<td>{{calculateAge Bdate}}</td>
<td>{{Sex}}</td>
<td>{{Level}}</td>
<td>{{formatName this.Teachers.Week1.Sunday}}</td>
<td>{{formatName this.Teachers.Week1.Monday}}</td>
<td>{{formatName this.Teachers.Week1.Tuesday}}</td>
<td>{{formatName this.Teachers.Week1.Wednesday}}</td>
<td>{{formatName this.Teachers.Week1.Thursday}}</td>
<td>{{formatName this.Teachers.Week1.Friday}}</td>
<td>{{formatName this.Teachers.Week1.Saturday}}</td>
</tr>
{{/if}}
{{/each}}
{{#each StudsWk1Master}}
{{#if curWeek 2}}
<tr>
<td>{{FullName}}</td>
<td>{{RoomWk2}}</td>
<td>{{calculateAge Bdate}}</td>
<td>{{Sex}}</td>
<td>{{Level}}</td>
<td>{{formatName this.Teachers.Week2.Sunday}}</td>
<td>{{formatName this.Teachers.Week2.Monday}}</td>
<td>{{formatName this.Teachers.Week2.Tuesday}}</td>
<td>{{formatName this.Teachers.Week2.Wednesday}}</td>
<td>{{formatName this.Teachers.Week2.Thursday}}</td>
<td>{{formatName this.Teachers.Week2.Friday}}</td>
<td>{{formatName this.Teachers.Week2.Saturday}}</td>
</tr>
{{/if}}
{{/each}}
</tbody>
</table>
{{/modalizeBody}}
</template>
您的助手未测试是否相等。你有:
{{#if curWeek 1}}
但是您的助手只是 return 当前一周,不需要参数。
只需将参数添加到您的辅助函数,然后 return 一个布尔值:
Template.Student.helpers({
curWeek: function (value) {
return Session.get('CurrentWeek').substr(0, 1) === value;
},