本文介绍了SyntaxError:编译ejs时,参数列表后缺少)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编译ejs时,在参数列表后出现错误:缺少)。
我尝试了很多次,但是找不到问题。

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

这是导致错误的ejs。
这段代码有什么问题?

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


推荐答案

在结束交易之前< / tr> ,该行

<% } %>

是多余的。因此,解析器将其解释为结束 forEach()的回调函数,而不提供进一步的参数或关闭函数调用的
圆括号。 (错误消息实际上是很清楚的,如果您考虑的话。:))

is superfluous. The parser therefore interprets this as ending the callback function of forEach() without providing further arguments or closing theround bracket of the function call. (The error message is actually pretty clear about what's going on, if you think about it. :))

通过这种方式,您还可以得到两个多余的> 收盘< / tbody> < / table>

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>>
<% } %>

这篇关于SyntaxError:编译ejs时,参数列表后缺少)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 02:01