gpt4 book ai didi

javascript - 语法错误 : missing ) after argument list in while compiling ejs

转载 作者:行者123 更新时间:2023-11-29 15:10:08 24 4
gpt4 key购买 nike

我在编译 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') %>

最佳答案

结束前 </tr> , 线

<% } %>

是多余的。因此,解析器将此解释为结束 forEach() 的回调函数。没有提供进一步的论据或关闭函数调用的圆括号。 (错误消息实际上很清楚发生了什么,如果你仔细想想。:))

顺便说一句,你还有两个多余的>在你结束的背后</tbody></table> .

这是您可以放入 https://ionicabizau.github.io/ejs-playground/ 中的工作固定代码示例

<%
var products = [
{title: "foobar", category: "things", image: "", _id: 1, price: 0}
];
var count = products.length;
%>
<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 (products.length > 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>>
<% } %>

关于javascript - 语法错误 : missing ) after argument list in while compiling ejs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55551264/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com