2016-06-14 28 views
0

我有一個模板助手返回一個會議的價值,在這種情況下它返回的人數1:流星使用Spacebars邏輯不服​​從邏輯

Template.Student.helpers({ 
    curWeek: function() { 
    return Session.get('CurrentWeek').substr(0, 1); 
}, 

我的模板有一個表,我試圖根據輔助函數的值將表中的一部分打印到表中。所以我在模板中有一些邏輯來打印正確的部分。但它不服從邏輯。即使curWeek的值返回值1,模板也會在{{#if curWeek 2}}下運行邏輯,所以兩者都在表中。我只希望{{#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> 

回答

1

你的幫手沒有測試平等。你有:

{{#if curWeek 1}} 

但是你的助手只是返回當前的一週,並不期望一個參數。

只需將參數添加到您的輔助函數,然後返回一個布爾值:

Template.Student.helpers({ 
    curWeek: function (value) { 
    return Session.get('CurrentWeek').substr(0, 1) === value; 
}, 
+0

嗯,是的。弗洛伊德先生再次幫我解救!謝謝你,先生。 –