Node.js

时间:2015-12-27 15:42:37

标签: node.js

我正在观看新波士顿的教程,我已经逐行检查,我看不出我的代码是如何不同的。我在这个页面中收到了一个意外的令牌错误。

当我在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>

3 个答案:

答案 0 :(得分:3)

解决了:

import {IUser} from './user.ts';
import {Document, Schema, Model} from 'mongoose';

// mixing in a couple of interfaces
interface IUserDocument extends IUser,  Document {}

// mongoose, why oh why '[String]' 
// TODO: investigate out why mongoose needs its own data types
let userSchema: Schema = new Schema({
  userName  : String,
  password  : String,
  firstName : String,
  lastName  : String,
  email     : String,
  activated : Boolean,
  roles     : [String]
});

// interface we want to code to?
export interface IUserModel extends Model<IUserDocument> {/* any custom methods here */}

// stumped here
export class User {
  constructor() {}
}

答案 1 :(得分:2)

您在循环(<%=)上使用echo(forEach),但每次循环(item.categoryName)时都没有输出:

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

我认为你应该交换它们,所以你在项目中使用<%=,而不是在循环中。

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

答案 2 :(得分:0)

我认为您在以下字符串中忘记了“=”:

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