Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala Play框架模板中的递归块_Scala_Playframework_Threaded Comments - Fatal编程技术网

Scala Play框架模板中的递归块

Scala Play框架模板中的递归块,scala,playframework,threaded-comments,Scala,Playframework,Threaded Comments,我正在为一篇博客文章编写一个模板,其中包含多线程评论。为线程注释编写模板的一种自然方式它使用递归方式来构造Html。大概是这样的: @showComment(comment: models.Comment) = { <div class="comment"> <div class="comment-metadata"> <span class="comment-author">by @comment.author

我正在为一篇博客文章编写一个模板,其中包含多线程评论。为线程注释编写模板的一种自然方式它使用递归方式来构造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>
}
@showcoment(注释:models.comment)={
作者@comment.author,
@注释.postedAt.格式(“dd-MMM-yy”)
详情:
@Html(comment.content.replace(“\n”和“
”) @注释过滤器{c=>c.parent_id==comment.id}map{ c=>@showcoment(c) } }
问题是使用递归块会产生错误:

引发的错误是:递归方法showComment需要结果类型

如果我尝试在showComment中放置返回类型,则会引发以下错误:

引发的错误为:未找到:值showcoment


任何解决方法?

在Scala中,递归方法需要返回类型:请参阅

我对Play框架不太了解(更像是一无所知),但请尝试:

@showComment(comment: models.Comment):Node = {
<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>
}
@showcoment(注释:models.comment):节点={
作者@comment.author,
@注释.postedAt.格式(“dd-MMM-yy”)
详情:
@Html(comment.content.replace(“\n”和“
”) @注释过滤器{c=>c.parent_id==comment.id}map{ c=>@showcoment(c) } }
这对我很有用:

@{}

@{

    //use regular scala here:
    def showComment(comment: models.Comment):Node = {
    ....
    }
    //the above just declared a recursive method, now call it:

   showComment(...)

}
  • 定义递归方法
  • 调用块末尾的方法
  • 利润
我可以通过将递归模板移动到自己的文件中来克服这个问题。

播放模板似乎不允许设置返回类型。因此根本没有递归。@FelipeHummel似乎有局限性。如果返回play.template.Html而不是节点,该怎么办?相同的错误:“引发的错误是:未找到:值showcoment”=\