[英]Create document after submit with meteor-autoform
我正在使用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
});
});
使用此程序包時要小心,不要過度復雜化您的應用程序邏輯並創建圓形掛鈎。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.