Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

recursive function in ejs #169

Closed
brucewar opened this issue Apr 23, 2014 · 7 comments
Closed

recursive function in ejs #169

brucewar opened this issue Apr 23, 2014 · 7 comments

Comments

@brucewar
Copy link

Can I define a recursive function and call it in ejs page? The following is my code:

<% 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>at<%= ret.comments[i].create_time %>say:</h4>
              <div class="comment"><%= ret.comments[i].comment %></div>
              <% createTree(ret.comments[i]); %>
            </div>
            <div class="btn btn-info btn-xs reply">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>at<%= ret.comments[i].create_time %>say:</h4>
              <div class="comment"><%= ret.comments[i].comment %></div>
            </div>
            <div class="btn btn-info btn-xs reply">reply</div>
          </div>
          <% } %>
        <% } %>
      <% } %>
    <% } %>
@brucewar
Copy link
Author

It's my code problem,I solve it.

@Globik
Copy link

Globik commented Sep 4, 2015

How you v solved it?)

@brucewar
Copy link
Author

brucewar commented Sep 8, 2015

my problem, syntax error

@brucewar brucewar closed this as completed Sep 8, 2015
@nicefella
Copy link

so, your code seems working as expected and that means ejs supports recursive templates?

@Globik
Copy link

Globik commented Oct 9, 2015

See here for recursive function at line 108
https://github.com/Globik/alikon/blob/master/view/files-manager.html

@salsa-project
Copy link

@brucewar TY for the block code of the recursive traversal function , i wasn't able to manage it in my project for 3 days TILL i tried your code ... TY

@SureshMGWeb
Copy link

Hi, can I see the working code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants