在meteor中用autoform添加postId注释

如何使用meteor-autoformpostId链接到注释中?

我努力了

 AutoForm.hooks({ insertCommentForm: { formToDoc: function(doc) { doc.postId = this.formAttributes.parentContext._id; return doc; }, } }); 

 AutoForm.hooks({ insertCommentForm: { formToDoc: function(doc) { doc.postId = Template.parentData(1)._id; return doc; }, } }); 

 AutoForm.hooks({ insertCommentForm: { before: { method: function(doc) { doc.postId = this.formAttributes.parentContext._id; return doc; } } } }); 

 AutoForm.hooks({ insertCommentForm: { before: { method: function(doc) { doc.postId = Template.parentData(1)._id; return doc; } } } }); 

postId是不确定的,不pipe我做什么。

编辑

我这样使用它:

 <template name="comment"> <div> <h1>{{_id}} {{title}}</h1> {{#if currentUser}} {{> quickForm collection="Comments" id="insertCommentForm" type="insert"}} {{/if}} .... 

所以_id应该可以访问。

编辑2

现在我试了

 before: { insert: function(doc, template) { doc.postId = Template.instance().post._id; console.log(doc); return doc; } }, 

并在我使用的模板

 {{> quickForm collection="Comments" id="insertCommentForm" type="insert" post=this template="bootstrap3-inline" label-class="sr-only"}} 

但后期是undefined所以我得到错误Uncaught TypeError: Cannot read property '_id' of undefined

而是使用你的

{{> quickForm collection =“Comments”id =“insertCommentForm”type =“insert”}}

你试一试

{{> quickForm collection =“Comments”id =“insertCommentForm”type =“insert”postId = _id}}

然后尝试通过帮助器访问这个值

Template.instance()。data.postId


您也可以将整个发布对象发送到子模板

{{> quickForm collection =“Comments”id =“insertCommentForm”type =“insert”post = this}}

然后通过访问权限访问该收集文档

(例如)

Template.instance()。data.post._id


这是通过模板访问数据的一个小例子

http://meteorpad.com/pad/Ke9DJnbvtsqjSHJy2/SimpleDataGivenThroughTemplates