這段代碼comment.reply.push(newReply),報錯:TypeError:Cannot read property 'push' of undefined
可能是數(shù)據(jù)模型沒有聲明對,記得是一個數(shù)組 才能調(diào)自身的.push方法 注意方括號[ { ... } ]
reply : [{
from : { type: ObjectId, ref : "User"},
to : { type :ObjectId, ref : "User" },
content : String
}],
可能是數(shù)據(jù)模型沒有聲明對,記得是一個數(shù)組 才能調(diào)自身的.push方法 注意方括號[ { ... } ]
reply : [{
from : { type: ObjectId, ref : "User"},
to : { type :ObjectId, ref : "User" },
content : String
}],
2017-12-01
看到這個評論報錯,我也遇到了,是自己寫的不對
Cannot read property 'reply' of null
要對模型的 _id 有概念 回復時 cid = commentID 這里commentID不是指回復人的id,而是這條評論數(shù)據(jù)本身的_id,查詢的id沒傳對,查不到數(shù)據(jù),自然就讀不到reply了
正確:data-cid="#{item._id}"
錯誤:data-cid="#{user._id}"
可參考我的項目:https://github.com/lancelot-song/Website-backstage-nodejs
求star ~~
Cannot read property 'reply' of null
要對模型的 _id 有概念 回復時 cid = commentID 這里commentID不是指回復人的id,而是這條評論數(shù)據(jù)本身的_id,查詢的id沒傳對,查不到數(shù)據(jù),自然就讀不到reply了
正確:data-cid="#{item._id}"
錯誤:data-cid="#{user._id}"
可參考我的項目:https://github.com/lancelot-song/Website-backstage-nodejs
求star ~~
2017-12-01
記得在發(fā)表評論的區(qū)域增加一個用戶登錄的判斷,否則不登錄會出現(xiàn)錯誤
另外我將username存在form標簽中,這樣ajax發(fā)布請求就不用讀數(shù)據(jù)庫的用戶名了,減少一些邏輯
if user
form(method="post", action="/movie/comment", id="commentForm", data-username="#{user.name}")
...
else
hr
h5 發(fā)表評論,請先登錄
另外我將username存在form標簽中,這樣ajax發(fā)布請求就不用讀數(shù)據(jù)庫的用戶名了,減少一些邏輯
if user
form(method="post", action="/movie/comment", id="commentForm", data-username="#{user.name}")
...
else
hr
h5 發(fā)表評論,請先登錄
2017-11-30
https://github.com/savoygu/movie-koa2 基于 koa2 做了上層邏輯重寫,歡迎star
2017-11-28
https://github.com/savoygu/movie-koa2 基于 koa2 做了上層邏輯重寫,歡迎star
2017-11-28
https://github.com/savoygu/movie 基于express4做了一些改進,歡迎star
2017-11-24