最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - SyntaxError: missing ) after argument list in while compiling ejs - Stack Overflow

programmeradmin0浏览0评论

I am getting the error: missing ) after argument list while piling ejs. I tried many times, but I can't find the problem.

Here's the ejs that causes errors. 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') %>

I am getting the error: missing ) after argument list while piling ejs. I tried many times, but I can't find the problem.

Here's the ejs that causes errors. 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') %>
Share Improve this question asked Apr 6, 2019 at 16:46 MirjanaMirjana 531 gold badge1 silver badge3 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 5

Before your closing </tr>, the line

<% } %>

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. (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>.

Here's a working fixed code example you can put into 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>>
<% } %>
发布评论

评论列表(0)

  1. 暂无评论