您好,我正在尝试使用ejs作为视图引擎来编辑nodejs中的数据,但它显示: D:\nodejs\crud\views\employee\addOrEdit.ejs:8,:ReferenceError how to ReferenceError,、,
通过点击下面的链接,我将进入编辑页面:
<a href="/employee/<%= this.id %>" class="btn btn-outline-warning my-2 my-sm-0">Edit</a>在编辑页面上,我得到了这个:
ReferenceError: D:\nodejs\crud\views\employee\addOrEdit.ejs:8
6| </h1>
7| <form action="/employee" method="POST">
>> 8| <input type="hidden" name="id" value="<%= employee.id %>">
9| <div class="form-group">
10| <label for="name">Fullname</label>
11| <input
employee is not defined
at eval (eval at compile
(D:\nodejs\crud\node_modules\ejs\lib\ejs.js:633:12), <anonymous>:11:26)
at returnedFn (D:\nodejs\crud\node_modules\ejs\lib\ejs.js:668:17)
at tryHandleCache (D:\nodejs\crud\node_modules\ejs\lib\ejs.js:254:36)
at View.exports.renderFile [as engine]
(D:\nodejs\crud\node_modules\ejs\lib\ejs.js:485:10)
at View.render (D:\nodejs\crud\node_modules\express\lib\view.js:135:8)
at tryRender
(D:\nodejs\crud\node_modules\express\lib\application.js:640:10)
at Function.render
(D:\nodejs\crud\node_modules\express\lib\application.js:592:3)
at ServerResponse.render
(D:\nodejs\crud\node_modules\express\lib\response.js:1012:7)
at ServerResponse.res.render (D:\nodejs\crud\node_modules\express-ejs-layouts\lib\express-layouts.js:77:18)
at router.get (D:\nodejs\crud\controllers\employeeController.js:7:6)
at Layer.handle [as handle_request]
(D:\nodejs\crud\node_modules\express\lib\router\layer.js:95:5)
at next (D:\nodejs\crud\node_modules\express\lib\router\route.js:137:13)
at Route.dispatch
(D:\nodejs\crud\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request]
(D:\nodejs\crud\node_modules\express\lib\router\layer.js:95:5)
at D:\nodejs\crud\node_modules\express\lib\router\index.js:281:22
at Function.process_params
(D:\nodejs\crud\node_modules\express\lib\router\index.js:335:12)addOrEdit.ejs:
<form action="/employee" method="POST">
<input type="hidden" name="id" value="<%= employee.id %>">
<div class="form-group">
<label for="name">Fullname</label>
<input
type="text"
id="name"
name="fullname"
class="form-control"
placeholder="Enter Full Name"
value="<%= typeof name != 'undefined' ? name : '' %>"
/>
</div>
<div class="form-group">
<label for="email">Email</label>
<input
type="email"
id="email"
name="email"
class="form-control"
placeholder="Enter Email"
value="<%= typeof email != 'undefined' ? email : '' %>"
/>
</div>
<div class="form-group">
<label for="password">Mobile</label>
<input
type="number"
id=""
name="mobile"
class="form-control"
placeholder="Mobile"
value=""
/>
</div>
<div class="form-group">
<label for="password2">City</label>
<input
type="text"
id="password2"
name="city"
class="form-control"
placeholder="City"
value=""
/>
</div>
<button type="submit" class="btn btn-primary btn-block">
Submit
</button>
<br>
<a href="/employee/list" class="btn btn-block btn-outline-info my-2 my-sm-0">view all</a>
</form>发布于 2019-08-23 13:10:10
您可以尝试包含这个CRUD + EJS + Mysql + NODE.js示例数据库表
https://stackoverflow.com/questions/57605952
复制相似问题