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