[英]Create document after submit with meteor-autoform
I am using meteor-autoform
. 我正在使用
meteor-autoform
。 I create my form with 我用创建表格
{{> quickForm collection="Messages" id="insertMessageForm" type="insert" fields="text"}}
It inserts the messages as it should but I also want to create a document in the Notification collection. 它按原样插入消息,但我也想在Notification集合中创建一个文档。 How can I make sure an notification is created every time a new message is created?
如何确保每次创建新消息时都创建通知? I want to create notification each time a new document is created in a collection all over my app.
每当我在整个应用程序的集合中创建新文档时,我都想创建通知。 How can this be done smartest?
如何做到最聪明? Can I create an afterCreate signal or something?
我可以创建一个afterCreate信号吗?
Use the meteor-core feature cursor.obsere
使用流星核心功能
cursor.obsere
lib/
Messages.observe({
added: function (doc) {
Notifications.insert({ text: 'New Message: ' + doc.text })
}
})
The doc
variable holds the new document that was inserted. doc
变量保存已插入的新文档。
I want to create notification each time a new document is created in a collection all over my app.
每当我在整个应用程序的集合中创建新文档时,我都想创建通知。
Then you should probably use this package : matb33:collection-hooks
然后,您可能应该使用以下软件包:
matb33:collection-hooks
You will be able to create hooks for each of your collections to create a notification when a new document is inserted. 您将能够为每个集合创建钩子,以在插入新文档时创建通知。
Comments.after.insert(function(userId, comment){
Notifications.insert({
userId: userId,
text: comment.text,
createdAt: comment.createdAt
});
});
Be careful when using this package to not overly complicate your application logic and create circular hooks. 使用此程序包时要小心,不要过度复杂化您的应用程序逻辑并创建圆形挂钩。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.