私はEmberJSを学んでいて、1レベルのサブコメントを許可するコメントセクションを構築しています。すべてのコメントを一覧表示する Ember View があります。特定のコメントで「返信」をクリックすると、ユーザーがサブコメントを書き込むためのテキストエリア入力が表示されます。
私のEmberJSコードでは、「返信」をクリックすると、特定のコメントだけでなく、すべてのコメントのテキストエリア入力が表示されます。アドバイスをいただければ幸いです:)
// 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>