たとえば、MeteorにMaterializeを使用して複数のカードパネルを生成するテンプレートがあります。重要なアイデアは、各パネル内で固有の値を生成することです。Meteorで動的イベントテンプレートを生成
<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>
「教師の名前」の長さによって、多くのパネルが作成されます。 @index構文を使用して一意の名前を生成します。私はイベントのテンプレートを作成する必要がある場合に
さて、私は必要があると思いことのようになります。、値のペア:
Template.Teacher_Information.events({
'click #img-0': function() {
// do some stuff
},
'click #image-1': function() {
// some more stuff
},
...
...
});
私は鍵を生成するためにテンプレート内のループのために挿入することはできません。だから、私はそれのような動的なイベントテンプレートをどのように生成することができるかについては、かなり止まっている。
私が今持っているものをすべて入れたら、oneTeacherテンプレートを表示できません。私はちょうど
のようなものを入れたら、oneTeacherのテンプレートを得ることができます。例えば、
の内容です。おそらくStudentList1のような追加の返された関数についての何か?わからない。しかし、あなたの答えは完全に意味があります。 –それは動作するようになった。テンプレートをレンダリングすることを許可していなかったのは、「@インデックス」の指定でした。私の質問は、教師ごとに設定された各ラジオボタンを一意にするように指定する方法です。そのパネルをクリックすると、そのパネルに関連付けられているラジオボタンが読み込まれます。私は「これ」が教師の対象をどのように参照しているのかを見ています。クリックするたびに各ラジオボタンが選択されます。あなたの助けに大変感謝します! –
ラジオボタンは 'name'でグループ化されています - それぞれのグループの名前として先生の' _id'を使用してください 'name = {{id}}' –