需要展现评论及其多级子评论,假设后台已获取了一个树形结构,那么使用freemarker该如何展现?
产生一个文件children.ftl,核心代码如下:
<#list list as comment>
<#if level==1>
<div <#if comment_index%2==1> style="background-color:#F5FAFE"</#if>>
</#if>
<div id="${comment.id}" >
<DIV id="parent" align="left" >
。。。。显示的内容。。。。。
</DIV>
<!--隐藏的回复div-->
<#include "/cn/videoplay/comment/commentWrapperDiv.ftl" >
<!--子评论-->
<div class="children" id="children_${comment.id}">
<#if comment.children?exists >
<#assign level=level+1 >
<#assign list=comment.children>
<#include "/cn/videoplay/comment/children.ftl" >
<#assign level=level-1 >
</#if>
</div>
</div>
<#if level==1>
</div>
</#if>
</#list>
客户端调用代码如下:
<#assign level=1>
<#include "/cn/videoplay/comment/children.ftl" >