[英]Express cannot read property
我的控制器:
exports.showit = function(req, res){
res.render('showpost', {
title: req.post.title,
post: req.post
})
}
我的帖子模型包括標題和名稱對象:
title: {type : String, default : '', trim : true},
name: {type : String, default : '', trim : true},
....and so on.
在ejs中,我嘗試通過以下方式到達帖子標題:
<h3><%= article.title %></h3>
而且我收到一個錯誤:“無法讀取未定義的屬性'title'”
我不知道是什么問題,請先謝謝您。
您沒有將article
變量傳遞給模板,僅將title
和post
傳遞給了模板。 所以使用這個:
<%= title %>
// or
<%= post.title %>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.