我想知道流星中的 abt DOM 操作。我的代码如下:
<template name = "studentList">
{{#each}}
<div class = "name">
Name: {{this.name}}
</div>
<div class = "age">
Age: {{this.age}}
</div>
<button class = "edit"> Edit </button>
{{/each}}
<button class = "addStudent"> Add Student </button>
</template>
Template.studentList.helpers({
studentlist:function(){
return Students.find();
}
});
Template.studentList.events({
//I am doing the DOM manupulation here based on the buttons clicked
});
我从数据库中获取学生信息列表并将它们显示在模板中。现在每个学生都有一个编辑按钮。当用户单击此编辑按钮时,我想将学生的“姓名”和“年龄”字段更改为文本字段,并提供“保存”和“取消”选项。
同样,我在模板末尾有一个“添加学生”按钮。当用户单击它时,我想显示一个表单,其中添加并保存了学生的姓名和年龄。
到目前为止,我能够做到这一点,但是通过在 studentList 的事件中使用大量 Jquery/Javascript 代码以一种非常天真的方式。我读了很多帖子说这不是正确的方法。
无论如何,请告诉如何在流星中实现此功能。或者只是一些可能的方法。
帮助表示赞赏。