ejs 模板中的意外标记

unexpected token in ejs template

请你帮我找出问题出在哪里

这是我的 ejs 文件中的代码,这就是问题所在

            <% if(user.account.deposits.length){ %>
              <% user.account.deposits.sort(sortFunction).map(history=>{ %>
               <% var className = history.approved ?  "text-success" : "text-warning" %>
               <%  status = history.approved ?  "approved" : "pending" %>
                <% return( %>
                  <tr>
                    <th scope="row"> <% history.sort %> </th>
                    <td class="<%= className %>"><%= status %></td>
                    <td><%= history.amount %><b> $</b></td>
                    <td> <%= history.date %></td>
                  </tr>
                <% )}) %>
           <%  }else{ %>
              <%  return ( %>
                  <tr>
                    <th scope="row">#</th>
                    <td class="text-light" colspan="3"> You have no deposit history</td>
                  </tr>
               <% ) } %>

使用 ejs-lint,我得到

进入控制台时出错

嗯,当 ejs 解析你的代码时,它会将它变成 javascript 没有 html 东西和这个

的代码

<% return( %><tr>

结果

... return( ; __append("\n ...

( 之后的 ; 导致错误。由于您根本不需要 return,您可以将其删除。

下面的代码应该可以工作

<% if(user.account.deposits.length){ %>
    <% user.account.deposits.sort(sortFunction).map(history=>{ %>
     <% var className = history.approved ?  "text-success" : "text-warning" %>
     <%  status = history.approved ?  "approved" : "pending" %>
    <tr>
        <th scope="row"> <% history.sort %> </th>
        <td class="<%= className %>"><%= status %></td>
        <td><%= history.amount %><b> $</b></td>
        <td> <%= history.date %></td>
    </tr>
      <% }) %>
 <%  }else{ %>
    <tr>
        <th scope="row">#</th>
        <td class="text-light" colspan="3"> You have no deposit history</td>
    </tr>
<% } %>