我的部分文件夹中有一个文件“productosofertas.ejs”,它包含在我的视图文件“ofertas.ejs”中。
这是ofertas.ejs代码:
<%- include("partials/head") -%>
<%- include("partials/header") -%>
<section class="d-block" style="margin-top: 180px;">
<div>
<img src="./images/publcidad-celenste.JPG" style="width: 100%;" alt="">
</div>
<div class="d-flex">
<img src="./images/publicidad-rosa.JPG" style="width: 50%;" alt="">
<img src="./images/publicidad-azul.JPG" style="width: 50%;" alt="">
</div>
</section>
<%- include("partials/productosofertas") -%>
<%- include("partials/footer") -%>
但是,每次我输入这个ejs文件的路径时,我的页面都会出现错误:
语法错误:C:\Users\VP\Desktop com\ECOMMERCE iews\ofertas.ejs:12 10|
11| </section>
12| <%- include("partials/productosofertas") -%>
13|
14| <%- include("partials/footer") -%>
编译 ejs 时,(我的 PC 路径)\ECOMMERCE iews\partials\productosofertas.ejs 中的参数列表后缺少 )
我尝试一次又一次地阅读代码以查找丢失的字符,但一切似乎都正常。我还在这里寻求与此相关的其他问题的帮助,但我仍然没有找到解决方案。
这是productosofertas.ejs代码:
<div class="others" style="margin-top: 2em;">
<div class="row">
<% ofertasrender.docs.forEach((elemento){ %>
<div class=" col-md-3 my-4">
<div class="position-relative" style="background-color: aliceblue;">
<img src="<%= elemento.imagen %>" alt="">
<% const texto = elemento.precio; %>
<% const regex = /(\d+)\s*(?=%)/g; %>
<% const descuento = texto.match(regex); %>
<% if (descuento) { %>
<p class="discount2-pageofertas"><%= descuento[0] %>% desc.</p>
<% } %>
</div>
<p class="other-title"><%= elemento.nombre %></p>
<p><%= elemento.precio.replace(elemento.nombre,'') %></p>
<div class="d-flex align-items-center justify-content-center">
<div class="product-counter other-product-counter">
<button class="counter-button other-counter-button">-</button>
<p>2</p>
<button class="counter-button other-counter-button">+</button>
</div>
<p><b>Añadir cantidad</b></p>
</div>
<button class="add-to-cart-btn other-add-to-cart-btn">Añadir al carrito</button>
<a href="/product?id=<%= elemento.id %>&coleccion=<%= elemento.coleccion %>"> ver producto</a>
</div>
<% }) %>
</div>
</div>
<nav aria-label="...">
<ul class="pagination pagination-sm justify-content-center">
<li class="page-item active" aria-current="page">
<a class="page-link" href="/ofertas?page=1&&a=1">1</a>
</li>
<% for ( var i = ofertasrender.page; i < ofertasrender.totalPages; i++) { %>
<% if(i<=a && i != 1){%>
<li class="page-item"><a class="page-link" href="/ofertas?page=<%=i%>&&llave=true&&a=<%=i%>"><%= i %></a></li>
<% } else if(i>a && i < ofertasrender.totalPages){ %>
<span>.</span>
<% } %>
<% } %>
<li class="page-item"><a class="page-link" href="#"><%= ofertasrender.totalPages %></a></li>
</ul>
</nav>
感谢您的阅读。
问题在于
.forEach
方法,回调函数语法不正确。
更换:
<% ofertasrender.docs.forEach((elemento){ %>
这样:
<% ofertasrender.docs.forEach((elemento)=>{ %>