0
我正在爲項目使用sails JS和Jade模板引擎。使用變量爲圖像src屬性渲染視圖時出現錯誤
我玉的觀點是:
h2.center= publication.title
img(src = publication.path) //- i've this error with this line
但在終端顯示的錯誤是:
Cannot read property 'title' of undefined
時,請檢查生成的I HTML一切都很好:
<h2 class="center">My title</h2>
<img src="img/publication2.png" />
謝謝您幫幫我 !
編輯1:
我有這個代碼在我的控制器:
find : function(req, res) {
Publication.findOne(req.param('id')).done(function(err, obj) {
if (err) {
console.log ("err", err)
} else {
return res.view({
publication : obj
})
}
})
},
EDIT 2,全面的錯誤跟蹤:
Error rendering view at ::
error: Using layout located at ::
error: Server Error (500)
error: TypeError: /home/toni/nodeJS/h2d/views/publication/find.jade:5
Cannot read property 'title' of undefined
只是爲了測試我更換
img(src = publication.path)
與
h2= plubication.path
,我已經沒有錯誤
請編輯您的問題 – Ven
心中已經編輯我的第一個問題 – amiceli
你完全確定'obj'不爲空? – Ven