1
我是nodejs的新手,通過構建一個小型項目(Blog)來學習它,當提交添加帖子表單細節時,面臨下面提到的問題。我還添加了addPost.jade和post.js的代碼。其獲取呈現罰款GET請求無法讀取undefined玉的屬性'長度'
TypeError: E:\Web projects\NodeJs projects\nodeBlog\views\addpost.jade:19
17| label Category:
18| select.form-control(name='category')
> 19| each cat, i in catList
20| option(value = '#{cat.title}') #{cat.title}
21| .form-group
22| label Body:
Cannot read property 'length' of undefined
at eval (eval at <anonymous> (E:\Web projects\NodeJs projects\nodeBlog\node_modules\jade\lib\index.js:218:8), <anonymous>:210:31)
at eval (eval at <anonymous> (E:\Web projects\NodeJs projects\nodeBlog\node_modules\jade\lib\index.js:218:8), <anonymous>:247:4)
at eval (eval at <anonymous> (E:\Web projects\NodeJs projects\nodeBlog\node_modules\jade\lib\index.js:218:8), <anonymous>:383:22)
at res (E:\Web projects\NodeJs projects\nodeBlog\node_modules\jade\lib\index.js:219:38)
at Object.exports.renderFile (E:\Web projects\NodeJs projects\nodeBlog\node_modules\jade\lib\index.js:380:38)
at Object.exports.renderFile (E:\Web projects\NodeJs projects\nodeBlog\node_modules\jade\lib\index.js:370:21)
at View.exports.__express [as engine] (E:\Web projects\NodeJs projects\nodeBlog\node_modules\jade\lib\index.js:417:11)
at View.render (E:\Web projects\NodeJs projects\nodeBlog\node_modules\express\lib\view.js:126:8)
at tryRender (E:\Web projects\NodeJs projects\nodeBlog\node_modules\express\lib\application.js:639:10)
at EventEmitter.render (E:\Web projects\NodeJs projects\nodeBlog\node_modules\express\lib\application.js:591:3)
at ServerResponse.render (E:\Web projects\NodeJs projects\nodeBlog\node_modules\express\lib\response.js:960:7)
at E:\Web projects\NodeJs projects\nodeBlog\routes\post.js:89:6
at Layer.handle [as handle_request] (E:\Web projects\NodeJs projects\nodeBlog\node_modules\express\lib\router\layer.js:95:5)
at next (E:\Web projects\NodeJs projects\nodeBlog\node_modules\express\lib\router\route.js:131:13)
at Immediate.<anonymous> (E:\Web projects\NodeJs projects\nodeBlog\node_modules\multer\lib\make-middleware.js:53:37)
at runCallback (timers.js:655:20)
addPost.jade文件
//Created by Sinner on 11-Apr-17.
extends layout
block content
h1=title
ul.errors
if errors
each error, i in errors
li.alert.alert-danger #{error.msg}
form(method='post', action='/posts/add', enctype='multipart/form-data')
.form-group
label Title:
input.form-control(name='title', type='text')
.form-group
label Category:
select.form-control(name='category')
each cat, i in catList
option(value = '#{cat.title}') #{cat.title}
.form-group
label Body:
textarea.form-control(name='body', id='body')
.form-group
label Main Image:
input.form-control(name='mainimage', type='file')
.form-group
label Author:
select.form-control(name='author')
option(value='Akshay Gupta') Akshay Gupta
option(value='Riddhi Tandon') Riddhi Tandon
input.btn.btn-default(name='Submit', type='submit', value='Save')
script(src='/ckeditor/ckeditor.js')
script CKEDITOR.replace('body')
post.js文件
請幫我解決這個問題,因爲我堅持這一點。
PS:也帖子越來越添加
感謝
你能告訴我該如何解決這個問題? –
我已經找到了問題,感謝您的幫助。 –
我已將註釋碼 //具體爲這一個 res.render('addpost',{ 「title」:「Add Post」 }); 和 req.location('/'); req.redirect( '/');這應該是res.location('/')和res.redirect('/') –