【发布时间】:2016-05-10 04:42:15
【问题描述】:
我有这个“评论”模板:
<template name="comment">
<li class="comment" id="{{_id}}" >
<div class="comment-wrapper level-{{level}}-comment">
<span id="reply-btn" class="reply-btn reply-btn-{{_id}}"><a href="#">reply</a></span>
<div class="content">
<p>{{body}}</p>
</div>
</div>
<div class="reply-to-comment reply-to-comment-{{_id}}" style="display:none;">
<form name="reply" class="reply-form">
<label for="reply_body">Reply to this comment</label>
<textarea name="reply_body"></textarea>
<button type="submit" class="btn">Post reply</button>
</form>
</div>
{{#if showChildComments}}
<ul class="comment-children comment-list">
{{#each childComments}}
{{> comment this}}
{{/each}}
</ul>
{{/if}}
</li>
</template>
与此comment.js 文件相关联(此处仅显示事件部分):
Template.comment.events({
"click #reply-btn": function(e, template){
console.log("Got in.")
$(".reply-to-comment-"+template.data._id).toggle();
}
});
现在,每次我点击回复时,它都会打开该特定评论的回复表单,如上面的模板所示。
这有效,但仅在“root”cmets 上有效,这意味着:如果我在回复“root”评论的回复上单击回复,console.log("Got in.") 将触发 3 次。如果是5级深度回复会触发5次,以此类推
我怀疑这是因为我在模板“comment”中渲染了模板“comment”。因此,流星正在监听许多“事件”......
但我不知道我怎么能做到这一点。那么,任何人都知道解决此问题的方法,或者更好的方法来实现我正在寻找的东西?
【问题讨论】:
标签: javascript jquery node.js meteor meteor-blaze