当前位置:K88软件开发文章中心编程语言JavaScriptMeteor → 文章内容

Meteor 评论

减小字体 增大字体 作者:佚名  来源:网上搜集  发布时间:2019-1-15 15:28:59

据库,以确保它再次运行。然后,我们要确保所有新帖子的评论计数从0开始://...var post = _.extend(postAttributes, { userId: user._id, author: user.username, submitted: new Date(), commentsCount: 0});var postId = Posts.insert(post);//...当我们创建一个新的评论时,使用 Mongo 的 $inc 操作(给一个数字字段值加一)更新相关的 commentsCount://...comment = _.extend(commentAttributes, { userId: user._id, author: user.username, submitted: new Date()});// 更新帖子的评论数Posts.update(comment.postId, {$inc: {commentsCount: 1}});return Comments.insert(comment);//...最后只需简单地删除 client/templates/posts/post_item.js 的 commentsCount helper,因为该值可以从帖子中得到。现在用户可以互相对话,如果他们错过了新的评论,这将是不可原谅的。接下来的章节将告诉你如何实现通知,以防止这个情况发生!

上一页  [1] [2] [3] 


Meteor 评论