[英]How to fix Cannot read property 'forEach' of null
\\views\\index.ejs:37
35|
36| <!-- Offers Section --> >>
37| <%- include("inc/content/offers") -%>
38| <!-- End Offers Section -->
39|
40| <!-- Menu Section -->
C:\\Users\\Marcos\\Desktop\\projeto\\restaurante\\views\\inc\\content\\offers.ejs:10
8|
9| <div class="row"> >>
10| <% menus.forEach((row)=>{%>
11| <div class="col-sm-4">
12| <div class="item">
13| <div class="discount"> Cannot read property 'forEach' of null
\\views\\index.ejs:37
35|
36| <!-- Offers Section -->
>> 37| <%- include("inc/content/offers") -%>
38| <!-- End Offers Section -->
39|
40| <!-- Menu Section -->
\\views\\inc\\content\\offers.ejs:10
8|
9| <div class="row">
>> 10| <% menus.forEach((row)=>{%>
11| <div class="col-sm-4">
12| <div class="item">
13| <div class="discount">
检查变量“菜单”是否设置
错误提示“菜单”为空。 我不确定您正在使用的技术。 但似乎 html 文件在您填充“菜单”变量之前呈现。
我认为您需要在 HTML 渲染之前填写“菜单”。 我建议您在“构造函数”生命周期钩子中填写变量,看看它是否可以帮助您摆脱错误。
确保 menus 是一个可枚举的,如果它是一个数组,确保你像这样运行你的循环<% menus.to_a.forEach((row)=>{%>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.