0
我正在學習EmberJS和建立一個評論部分,允許1級別的評論。我有一個Ember視圖列出了所有的評論,當你點擊一個特定評論的「回覆」時,它應該顯示一個textarea輸入,供用戶編寫一個子評論。在EmberJS我的事件觸發所有的子視圖,而不是隻有目標的一個
在我的EmberJS代碼中,當你點擊「回覆」時,它會顯示所有註釋的textarea輸入,而不僅僅是特定的註釋。任何意見,將不勝感激:)
// View
App.commentsView = Em.View.create({
templateName: 'commentsTmpl',
showReply: false,
reply: function(e) {
e.view.set('showReply', true);
e.preventDefault();
}
});
App.replyCommentsView = Em.View.extend({
showReplyBinding: 'App.commentsView.showReply'
});
// Template
<script data-template-name="commentsTmpl" type="text/x-handlebars">
</h2>comment</h2>
{{#each App.commentsController}}
<div class="comment-group clearfix">
<div class="comment">
<img class="comment-pic" {{bindAttr src="userPic"}} alt="user pic">
<div class="comment-content">
<a href="#" class="comment-username">{{userName}}</a>
<span class="comment-body">{{text}}</span>
<div class="comment-actions clearfix">
<a href="#" {{action "reply"}}>Reply</a>
</div>
</div>
</div>
{{#view App.replyCommentsView}}
{{#if showReply}}
<div class="comment-reply">
<h2>sub-comment</h2>
<textarea class="txt-comment-reply" rows="2" cols="65"></textarea>
</div>
{{/if}}
{{/view}}
</div>
{{/each}}
</script>