projects.html
{{#if projects}}
{{#each projects}}
<div class="project-item">
<div class="project-name">
{{name}}
</div>
<div class="project-settings">
<span class="rename">Rename</span>
<span class="edit">Edit</span>
<span class="delete">
<!-- Here -->
</span>
</div>
</div>
{{/each}}
{{/if}}
projects.js
Template.Projects.events({
"click .project-item .delete": function (e, template) {
e.preventDefault();
debugger
// "this" refers to the specific project
}
});
在事件处理程序中,我注意到“this”方便地引用模板中与事件相关的特定对象。例如,在这种情况下,删除按钮位于each projects
块内,删除按钮的处理程序具有this = some project
。这很方便,但我想更全面地了解范围和规则。有人可以简要解释并指出我正确的文件吗?