【发布时间】:2020-07-11 18:44:38
【问题描述】:
有一个被模板包裹的表格。我想要做的是从该表的指定字段中获取值以及表单中的值。每行都有一个按钮来传递值。但是当我试图在控制台中打印出来时,它说它是未定义的。 因此,任何人都对此有解决方案或更好的方法,我将不胜感激。
到目前为止,我已经尝试使用serializeArray()。但是,它似乎无法从 <td> 元素中获取值。
<template name="student">
{{#each student}}
<tr>
<td>{{name}}</td>
<td>{{studentID}}</td>
<td><textarea rows="1"></textarea></td>
<td><input type="submit" class="btn btn-primary markAttendance"></td>
</tr>
{{/each}}
</template>
<template name="subject">
<select id="dropdown" name="dropdown" class="form-control">
<option>Please select a subject</option>
{{#each subject}}
<option>{{subjectCode}}</option>
{{/each}}
</select>
</template>
事件处理程序:
Template.content.events({
'click .markAttendance':function(e){
e.preventDefault();
var subjectCode = $(e.target).find('[name=dropdown]').val();
var week = $(e.target).find('[name=week]').val();
var studentName = $(e.target).find('td:eq(0)').text();
var studentID = $(e.target).find('td:eq(1)').text();
console.log(subjectCode);
console.log(week);
console.log(studentName);
console.log(studentID);
//.....
}
});
【问题讨论】:
标签: javascript jquery meteor meteor-blaze