EJS templates: How to generate an HTML tree structure in the most elegant and handy way

北慕城南 提交于 2019-12-04 10:10:48

I found a better approach, but it need a separate EJS file.

In my main.ejs:

<%- partial('treeView', {items: tree}) %>

In the treeView.ejs:

<% if (items.length) { %>
<ul>
<% } %>

    <% items.forEach(function(item){ %>
    <li>
        <a href="<%= item.link %>"><%= item.name %></a>
        <%- partial('treeView', {items: item.children}) %>
    </li>
    <% }) %>

<% if (items.length) { %>
</ul>
<% } %>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!