无法阅读财产' forEach'未定义的node.js

时间:2017-06-11 15:36:11

标签: node.js express foreach

我在此代码上遇到.forEach()错误

```<% if(locals.isAuthenticated) { %>
  <section>
    <h4>Leave a comment</h4>
    <form method="POST" action="/landmarks/<%= landmark.id %>/comments">
      <textarea name="content" id="content" placeholder="Comment"></textarea>
      <button class="button">Leave a comment</button>
    </form>
  </section>
<% } %>

<section>
  <h4>Comments</h4>
  <% landmark.comments.forEach((comment) => { %>
    <p><%= comment.content %></p>
    <small><%= comment.createdBy.username %></small>
    <small><%= comment.createdAt.toDateString() %></small>

    <% if(locals.isAuthenticated && comment.belongsTo(user)) { %>
      <form method="POST" action="/landmarks/<%= landmark.id %>/comments/<%= comment.id %>">
        <input type="hidden" name="_method" value="DELETE">
        <button class="btn">Delete Comment</button>
      </form>
    <% } %>
  <% }) %>
</section>```

我不确定为什么会发生这种情况因为我认为这是forEach方法的正确语法

0 个答案:

没有答案