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}}' –