帖子中的嵌套评论

时间:2016-06-18 08:10:33

标签: ember.js

我正在开发一个ember应用程序,我想在帖子中允许嵌套注释。

为此,我创建了一个Component来显示帖子中的每条评论。在这个组件中,我做了一个递归调用来显示"嵌套注释"

<article class="post-comment">

  <p> {{comment.text}}  commented by {{comment.user.name}} {{moment-from-now comment.date }} </p>

  {{input id=comment.id  class="form-control" placeholder=(t "enter.title") value=commentCommentText}}

  <button class="btn " {{action "doComment" comment commentCommentText}}>comment</button>
  {{#if (can "delete comment")}}
    <button class="btn btn-danger " {{action "deleteComment" comment }}>delete</button>
  {{/if}}

  {{#if comment.comments.length}}
   {{#each comment.comments as |nestedComment| }}
    <p>{{nestedComment.text}}</p>
      {{#post-comment comment=nestedComment action="commentComment" cancel="deleteComment"}} {{/post-comment}}
   {{/each}}
  {{/if}}

</article>

从模板中调用它是这样的:

{{#each post.comments as |postComment| }}

   <li class="media list-group-item p-a">
     {{#post-comment comment=postComment submit="commentComment" cancel="deleteComment"}} 
     {{/post-comment}}

   </li>
{{/each}}

但它给了我一个Uncaught RangeError: Maximum call stack size exceeded。老实说,我不知道这种递归调用是否是最好的方法。任何想法如何实现这一目标?

0 个答案:

没有答案