简体   繁体   English

SyntaxError: missing ) 在编译 ejs 时的参数列表之后

[英]SyntaxError: missing ) after argument list in while compiling ejs

I am getting the error: missing ) after argument list while compiling ejs.我在编译 ejs 时在参数列表之后收到错误:缺少 )。 I tried many times, but I can't find the problem.我尝试了很多次,但我找不到问题所在。

Here's the ejs that causes errors.这是导致错误的 ejs。 What is the problem with this code?这段代码有什么问题?

<%- 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') %>

Before your closing </tr> , the line在您关闭</tr> ,该行

<% } %>

is superfluous.是多余的。 The parser therefore interprets this as ending the callback function of forEach() without providing further arguments or closing the round bracket of the function call.因此,解析器将此解释为结束forEach()的回调函数,而不提供进一步的参数或关闭函数调用的圆括号。 (The error message is actually pretty clear about what's going on, if you think about it. :)) (如果您仔细想想,错误消息实际上很清楚发生了什么。:))

By the way you also got two superflous > behind your closing </tbody> and </table> .顺便说一句,你也有两个superflous >您的交易背后</tbody></table>

Here's a working fixed code example you can put into https://ionicabizau.github.io/ejs-playground/这是一个有效的固定代码示例,您可以将其放入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>>
<% } %>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 EJS ERROR: SyntaxError: missing ) 在编译 ejs 时参数列表后 - EJS ERROR: SyntaxError: missing ) after argument list in while compiling ejs 语法错误:在编译 ejs 时缺少参数列表 - SyntaxError: missing ) after argument list while compiling ejs 是什么原因导致在编译ejs时views \\ contact-form.ejs中的参数列表后出现“ SyntaxError:missing”错误? - What may be causing the “SyntaxError: missing ) after argument list in views\contact-form.ejs while compiling ejs” error? 编译 ejs 时,在 C:\\Users\\computer point\\Desktop\\project2\\views\\home.ejs 中的参数列表后出现 ejs 错误 SyntaxError: missing ) - Having ejs error SyntaxError: missing ) after argument list in C:\Users\computer point\Desktop\project2\views\home.ejs while compiling ejs 编译 ejs 时在 partials\messages.ejs 中的参数列表后缺少 ) - Missing ) after argument list in partials\messages.ejs while compiling ejs 语法错误:缺少 ) 参数列表后 - SyntaxError: missing ) after argument list 参数列表后出现SyntaxError:缺少) - SyntaxError: missing ) after argument list 参数列表后未捕获到的SyntaxError:缺少)(调用js函数时) - Uncaught SyntaxError: missing ) after argument list (while calling a js function) 未捕获的语法错误:在使用 onclick 事件时参数列表后缺少 ) - Uncaught SyntaxError: missing ) after argument list while using onclick event 使用LZMA-js时,参数列表后出现SyntaxError:缺少) - SyntaxError: missing ) after argument list while using LZMA-js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM