ejs中可以声明递归函数吗?代码如下,createTree是一个递归函数。
<% function createTree(ret){ %>
<% if(ret.comments){ %>
<% var i = -1, len = ret.comments.length %>
<% while(++i < len){ %>
<% if(ret.comments[i].comments) { %>
<% console.log(ret.comments[i]); %>
<div class="media" id="<%= ret.comments[i]._id %>">
<a class="pull-left">
<img class="media-object" src="<%= ret.comments[i].gravatar %>">
</a>
<div class="media-body">
<h4 class="media-heading text-muted "><a href="<%= ret.comments[i].site %>" rel="nofollow"><%= ret.comments[i].name %></a>于<%= ret.comments[i].create_time %>说道:</h4>
<div class="comment"><%= ret.comments[i].comment %></div>
<% createTree(ret.comments[i]); %>
</div>
<div class="btn btn-info btn-xs reply">回复</div>
</div>
<% } else { %>
<% console.log(ret.comments[i]); %>
<div class="media" id="<%= ret.comments[i]._id %>">
<a class="pull-left">
<img class="media-object" src="<%= ret.comments[i].gravatar %>">
</a>
<div class="media-body">
<h4 class="media-heading text-muted "><a href="<%= ret.comments[i].site %>" rel="nofollow"><%= ret.comments[i].name %></a>于<%= ret.comments[i].create_time %>说道:</h4>
<div class="comment"><%= ret.comments[i].comment %></div>
</div>
<div class="btn btn-info btn-xs reply">回复</div>
</div>
<% } %>
<% } %>
<% } %>
<% } %>