使用流星自动成型提交后创建文档

Create document after submit with meteor-autoform

本文关键字:提交 创建 文档 成型 流星      更新时间:2023-09-26

我正在使用meteor-autoform。我用创建表单

{{> quickForm collection="Messages" id="insertMessageForm" type="insert" fields="text"}}

它按照应该的方式插入消息,但我也想在Notification集合中创建一个文档。如何确保每次创建新消息时都会创建通知?我希望每次在我的应用程序中的集合中创建新文档时都创建通知。如何做到这一点最明智?我可以创建一个afterCreate信号吗?

使用流星核心功能cursor.obsere

lib/

Messages.observe({
  added: function (doc) {
    Notifications.insert({ text: 'New Message: ' + doc.text })
  }
})

doc变量保存插入的新文档。

我希望每次在我的应用程序上到处都是收藏。

那么你可能应该使用这个包:matb33:collection-hooks

您将能够为每个集合创建挂钩,以便在插入新文档时创建通知。

Comments.after.insert(function(userId, comment){
  Notifications.insert({
    userId: userId,
    text: comment.text,
    createdAt: comment.createdAt
  });
});

使用此包时要小心,不要使应用程序逻辑过于复杂并创建循环挂钩。