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,我得到
- views/profile/deposit.ejs 中的意外标记 (86:32)
"><%=状态%>
进入控制台时出错
- 语法错误:意外的标记“;”在 C:######\views\profile\deposit.ejs 中编译 ejs *
我已经检查过,但找不到错误所在
嗯,当 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>
<% } %>
请你帮我找出问题出在哪里
这是我的 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,我得到
- views/profile/deposit.ejs 中的意外标记 (86:32) "><%=状态%>
进入控制台时出错
- 语法错误:意外的标记“;”在 C:######\views\profile\deposit.ejs 中编译 ejs * 我已经检查过,但找不到错误所在
嗯,当 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>
<% } %>