0
假設我在Meteor中有一個模板,它使用Materialize生成多個卡面板。關鍵的想法是它在每個面板內部生成獨特的值。在流星中生成動態事件模板
<template name="Teacher_Information">
{{#each TeacherNames}}
<div class="row">
<div class="col s12">
<div class="card blue-grey darken-1">
<div class="card-content white-text">
<a href="#" id="img-{{@index}}"><img src={{formatImage FullName}} alt="" class="circle"></a>
<span class="card-title">{{formatName FullName}}</span>
<span>Some text here.</span>
<span>
<form>
<input name="dayGroup" type="radio" id="teach-sunday-{{@index}}" value="Sunday">
<label for="teach-sunday-{{@index}}" class="white-text">SU</label>
<input name="dayGroup" type="radio" id="teach-monday-{{@index}}" value="Monday">
<label for="teach-monday-{{@index}}" class="white-text">MO</label>
<input name="dayGroup" type="radio" id="teach-tuesday-{{@index}}" value="Tuesday">
<label for="teach-tuesday-{{@index}}" class="white-text">TU</label>
<input name="dayGroup" type="radio" id="teach-wednesday-{{@index}}" value="Wednesday">
<label for="teach-wednesday-{{@index}}" class="white-text">WE</label>
<input name="dayGroup" type="radio" id="teach-thursday-{{@index}}" value="Thursday">
<label for="teach-thursday-{{@index}}" class="white-text">TH</label>
<input name="dayGroup" type="radio" id="teach-friday-{{@index}}" value="Friday">
<label for="teach-friday-{{@index}}" class="white-text">FR</label>
</form>
</span>
</div>
<div class="card-action white-text">
<form class="input-field col s6 card-selector">
<select multiple id="teacher-students-day1-{{@index}}">
<option value="" disabled selected>Select Students</option>
{{#each StudentList1}}
<option value= '{{FullName}}'>{{formatName FullName}} ({{Level}})</option>
{{/each}}
</select>
</form>
<form class="input-field col s2 card-selector">
<select multiple id="days-off-{{@index}}">
<option value="" disabled selected>Off</option>
<option value="Sunday">Su</option>
<option value="Monday">Mo</option>
<option value="Tuesday">Tu</option>
<option value="Wednesday">We</option>
<option value="Thursday">Th</option>
<option value="Friday">Fr</option>
<option value="Saturday">Sa</option>
</select>
</form>
</div>
</div>
</div>
</div>
{{/each}}
</template>
根據'TeacherNames'的長度,它會創建很多面板。它使用@index語法來生成唯一的名稱。
現在,當我需要創建事件模板,什麼我需要會是這樣的:
Template.Teacher_Information.events({
'click #img-0': function() {
// do some stuff
},
'click #image-1': function() {
// some more stuff
},
...
...
});
我不能循環插入模板內生成密鑰:值對,所以我幾乎停滯不前,無法生成類似的動態事件模板。
我無法讓oneTeacher模板顯示,當我把它放在裏面,我現在有。例如,我可以獲得oneTeacher模板,以顯示我是否放入了像
某些內容
之類的內容。或許有關像StudentList1這樣的額外返回函數?不確定。但是你的回答總是有道理的。 –得到它的工作。這是'@index'指定,不允許模板呈現。我的問題是如何指定每個教師設置的每個單選按鈕是唯一的,因此當用戶單擊該面板時,會讀取與該面板關聯的單選按鈕。我明白'這'是指教師的對象。每次點擊都應該獲得每個單選按鈕選擇。非常感謝您的幫助! –
單選按鈕按'name'分組 - 只需使用老師的'_id'作爲每個組的名稱'name = {{_ id}}' –