MongoDB读取数据,之后通过res.json()传递到前端读取不到create_at_ago()函数???
各位大大好,我有一个问题,我保存一个比如回答的评论信息到MongoDB之后,会得到保存的文档也就是answerComment
,但是我在后台通过console输出可以得到newAnswerComment.create_at_ago()
是有时间的比如几秒前
,但是通过下面代码中的res.json()
传到前端的时候就读取不到了,报错create_at_ago is not a function
请问各位这是什么原因,着实搞了好几天还没明白,找了很多资料,很迷茫,拜谢了
AnswerComment.newAndSave(answer_id, author_id, content, master_id, function (err, answerComment) {
if (err) next(err);
var proxy = new EventProxy();
proxy.all('answer_ready', 'author_ready', function () {
console.log(newAnswerComment.create_at_ago())
res.status(200).json({resultFromServer: "successCreateComment", answerComment: answerComment});
});
// 更新回答的评论数量
Answer.getAnswerWithoutUserById(answerComment.answer_id, function (err, answer) {
if (err) next(err);
// answer.comment_count++;
answer.save(function (err) {
if (err) next(err);
proxy.emit('answer_ready');
});
});
####newAndSave方法详情
exports.newAndSave = function (answer_id, author_id, content, master_id, callback) {
var answerComment = new AnswerComment();
answerComment.answer_id = answer_id;
answerComment.author_id = author_id;
answerComment.content = content;
answerComment.master_id = master_id || null;
answerComment.save(callback);
};