我正在为博客文章编写模板,其中包含线程评论。为线程注释编写模板的一种自然方式是使用递归方式构建 Html。像这样的东西:
@showComment(comment: models.Comment) = {
<div class="comment">
<div class="comment-metadata">
<span class="comment-author">by @comment.author,</span>
<span class="comment-date">
@comment.postedAt.format("dd MMM yy")
</span>
</div>
<div class="comment-content">
<div class="about">Detail: </div>
@Html(comment.content.replace("\n", "<br>"))
</div>
<a href="@action(controllers.Application.replyComment(comment.id()))">Reply</a>
@comments filter { c => c.parent_id == comment.id } map {
c => @showComment(c)
}
</div>
}
问题是使用递归块会产生错误:
引发的错误是:递归方法 showComment 需要结果类型
如果我尝试在 showComment 中输入返回类型,则会引发此错误:
引发的错误是:未找到:值 showComment
任何解决方法?