- ·上一篇文章:Meteor 创建 Meteor Package
- ·下一篇文章:Meteor 非规范化
当前位置:K88软件开发 → 文章中心 → 编程语言 → JavaScript → Meteor → 文章内容
Meteor 评论
据库,以确保它再次运行。然后,我们要确保所有新帖子的评论计数从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,因为该值可以从帖子中得到。现在用户可以互相对话,如果他们错过了新的评论,这将是不可原谅的。接下来的章节将告诉你如何实现通知,以防止这个情况发生!
Meteor 评论