簡體   English   中英

Node.js中的意外令牌)

[英]Unexpected token ) in in Node.js

我正在看新波士頓的教程,並且逐行進行檢查,看不到我的代碼有何不同。 我在此頁面中收到意外的token)錯誤。

當我在foreach中的fucntion(item)中的項目之后刪除)時,它說出意外的標記{。 因此,我不確定從這一點出發。 我想念一些小東西嗎?

編輯:我正在添加我在代碼中的頁面上得到的錯誤,因為它已經發表了很多評論。

EDIT2:添加了header.ejs

header.ejs

<a href="/">Home</a> |
<a href="/about">About</a> |
<a href="#">Link 3</a>

Unexpected token ) in c:\Users\Amazo\WebstormProjects\Project1Express\views\index.ejs while compiling ejs

SyntaxError: Unexpected token ) in c:\Users\Amazo\WebstormProjects\Project1Express\views\index.ejs while compiling ejs
    at Function (native)
    at Object.Template.compile (c:\Users\Amazo\WebstormProjects\Project1Express\node_modules\ejs\lib\ejs.js:464:12)
    at Object.compile (c:\Users\Amazo\WebstormProjects\Project1Express\node_modules\ejs\lib\ejs.js:288:16)
    at handleCache (c:\Users\Amazo\WebstormProjects\Project1Express\node_modules\ejs\lib\ejs.js:147:16)
    at View.exports.renderFile [as engine] (c:\Users\Amazo\WebstormProjects\Project1Express\node_modules\ejs\lib\ejs.js:350:14)
    at View.render (c:\Users\Amazo\WebstormProjects\Project1Express\node_modules\express\lib\view.js:126:8)
    at tryRender (c:\Users\Amazo\WebstormProjects\Project1Express\node_modules\express\lib\application.js:639:10)
    at EventEmitter.render (c:\Users\Amazo\WebstormProjects\Project1Express\node_modules\express\lib\application.js:591:3)
    at ServerResponse.render (c:\Users\Amazo\WebstormProjects\Project1Express\node_modules\express\lib\response.js:961:7)
    at c:\Users\Amazo\WebstormProjects\Project1Express\routes\index.js:6:7

<!DOCTYPE html>
<html>
  <head>
    <title><%= title %></title>
    <link rel='stylesheet' href='/stylesheets/style.css' />
  </head>
  <body>

  <% include templates/header.ejs %>
    <h1><%= title %></h1>
    <h1><%= points %></h1>
  <h3><%= videodata.categoryName %></h3>
  <p>My name is <%= name %> and I am <%= age %> years old. My occupation is being a <%= occupation %>.</p>
  <ul>
    <%= videodata.categories.forEach(function(item) {  %>
      <li><% item.categoryName %></li>
    <% }); %>
  </ul>
  </body>
</html>

解決了 :

<% videodata.categories.forEach(function(item) {  %>
  <li><%= item.categoryName %></li>
<% }) %>

在這里,您在循環( forEach )上使用echo( <%= ),但不是每次通過循環( item.categoryName )都用於輸出:

<%= videodata.categories.forEach(function(item) {  %>
  <li><% item.categoryName %></li>
<% }); %>

我認為您應該交換它們,因此您在項目中使用了<%= ,而不是在循環中使用。

<% videodata.categories.forEach(function(item) {  %>
  <li><%= item.categoryName %></li>
<% }); %>

我認為您在以下字符串中忘記了“ =”:

 <li><%= item.categoryName %></li>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM