简体   繁体   中英

Why EJS generates spaces between each iteration of a forEach loop?

EJS generates spaces between each iteration of a forEach loop.

Here is my code:

   <tr>
        <th scope="row">Autre(s) demandeur(s) (membre)</th>
        <td>
            <% request.other_full_members.forEach(function (member, i){ %>
            <%= member.name%><% if (i !== request.other_full_member.length -1) { %>,<% } %>
            <% }) %>
        </td>
    </tr>

And the result look like this: 在此处输入图像描述

This is not a problem for the display of the page. The problem comes when I want to export the table to.xlsx. The file is filled with unnecessary space.

The spaces in your template are being displayed. Try something like this:

<tr>
  <th scope="row">Autre(s) demandeur(s) (membre)</th>
  <td>
    <%
      request.other_full_members.forEach(function (member, i){
    %><%=
      member.name%><% if (i !== request.other_full_member.length -1) { %>,<% }
    %><%
      })
    %>
  </td>
</tr>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM