我正在使用meteor-autoform。我使用创建我的表单
{{> quickForm collection="Messages" id="insertMessageForm" type="insert" fields="text"}}它按应插入的方式插入消息,但我还想在Notification集合中创建一个文档。如何确保每次创建新邮件时都会创建通知?我希望每次在我的应用程序中的集合中创建新文档时都会创建通知。如何才能最明智地做到这一点?我可以创建一个afterCreate信号或其他东西吗?
发布于 2015-06-29 05:03:09
使用meteor-core特性cursor.obsere
lib/
Messages.observe({
added: function (doc) {
Notifications.insert({ text: 'New Message: ' + doc.text })
}
})doc变量保存插入的新文档。
发布于 2015-06-29 04:55:10
我希望每次在我的应用程序中的集合中创建新文档时创建通知。
那么您可能应该使用这个包:matb33:collection-hooks
您将能够为每个集合创建挂钩,以便在插入新文档时创建通知。
Comments.after.insert(function(userId, comment){
Notifications.insert({
userId: userId,
text: comment.text,
createdAt: comment.createdAt
});
});使用此包时要小心,不要使应用程序逻辑过于复杂并创建循环挂钩。
https://stackoverflow.com/questions/31104543
复制相似问题