Mir*_*ana 5 javascript syntax-error ejs
我在编译 ejs 时在参数列表之后收到错误:缺少 )。我尝试了很多次,但我找不到问题所在。
这是导致错误的 ejs。这段代码有什么问题?
<%- include('../_layouts/adminheader') %>
<h2 class='page-title'>Products</h2>
<br>
<a href="/admin/products/add-product" class="btn btn-primary">Add a new product</a>
<br><br>
<% if (count > 0) { %>
<table class="table table-striped">
<thead>
<tr class="home">
<th>Product</th>
<th>Price</th>
<th>Category</th>
<th>Product Image</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<% products.forEach(function(product) { %>
<tr>
<td><%= product.title %></td>
<td>$<%= parseFloat(product.price).toFixed(2) %></td>
<td><%= product.category %></td>
<td>
<% if (product.image == "") { %>
<img src="/images/noimage.png">
<% } else { %>
<img src="product_images/<%= product._id %>/<%= product.image %>">
<% }%>
</td>
<td><a href="/admin/products/edit-product/<%= product._id %>">Edit</a></td>
<td><a href="/admin/products/delete-product/<%= product._id %>" onclick="return confirm('Are you sure you want to delete this item?');">Delete</a></td>
<% } %>
</tr>
<% }); %>
</tbody>>
</table>>
<% } else { %>
<h3 class="text-center">There are no products.</h3>>
<% } %>
<%- include('../_layouts/adminfooter') %>
Run Code Online (Sandbox Code Playgroud)
在您关闭之前</tr>,该线路
<% } %>
Run Code Online (Sandbox Code Playgroud)
是多余的。因此,解析器将其解释为结束回调函数,forEach()而不提供进一步的参数或关闭函数调用的圆括号。(如果你仔细想想,错误消息实际上很清楚地说明了发生了什么。:))
>顺便说一下,你的结束语后面还有两个多余的</tbody>和</table>。
这是一个有效的固定代码示例,您可以将其放入https://ionicabizau.github.io/ejs-playground/
<% } %>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8208 次 |
| 最近记录: |