NodeJS ejs删除for循环中td元素之间的换行符

41zrol4v  于 2023-06-22  发布在  Node.js
关注(0)|答案(1)|浏览(160)

我想在for循环中呈现<th>,th中的内容是变量。但是当呈现HTML时,每个<th>之间有许多换行符。我不是在问如何使用<% -%>修剪模式删除可变换行符。

<thead>
     <th class="yellow-field"></th>
      <% blockUnitDetail.UnitArr.forEach(unit=>{ %>
         <th class="yellow-field"><%= unit %></th>
      <% }) %>
  </thead>

HTML:

<thead>
      <th class="yellow-field"></th>
        
      <th class="yellow-field">A1</th>
        
      <th class="yellow-field">A2</th>
        
      <th class="yellow-field">A3</th>
xpcnnkqh

xpcnnkqh1#

控制流代码if else ...将占据HTML中的一行。因此,应该使用空白修剪模式(slurp所有空格)的控制流<%_ _%>

<thead>
        <th class="yellow-field"></th>
        <%_ blockUnitDetail.UnitArr.forEach(unit=>{ _%>
            <th class="yellow-field"><%= unit %></th>
        <%_ }) _%>
  </thead>

相关问题