作者:fionafongkaian | 来源:互联网 | 2023-08-27 14:51
HowcanIlinkaddpostIdtocommentswhenusingmeteor-autoform?使用meteor-autoform时,如何将postId链接到注释?
How can I link add postId
to comments when using meteor-autoform
?
使用meteor-autoform时,如何将postId链接到注释?
I have tried
我努力了
AutoForm.hooks({
insertCommentForm: {
formToDoc: function(doc) {
doc.postId = this.formAttributes.parentContext._id;
return doc;
},
}
});
and
AutoForm.hooks({
insertCommentForm: {
formToDoc: function(doc) {
doc.postId = Template.parentData(1)._id;
return doc;
},
}
});
and
AutoForm.hooks({
insertCommentForm: {
before: {
method: function(doc) {
doc.postId = this.formAttributes.parentContext._id;
return doc;
}
}
}
});
and
AutoForm.hooks({
insertCommentForm: {
before: {
method: function(doc) {
doc.postId = Template.parentData(1)._id;
return doc;
}
}
}
});
but postId
is undefined no matter what I do.
但无论我做什么,postId都是不确定的。
Edit
I use it like this:
我这样使用它:
{{_id}} {{title}}
{{#if currentUser}}
{{> quickForm collection="Comments" id="insertCommentForm" type="insert"}}
{{/if}}
....
so _id
should be accessible.
所以_id应该是可访问的。
Edit 2
Now I have tried
现在我试过了
before: {
insert: function(doc, template) {
doc.postId = Template.instance().post._id;
console.log(doc);
return doc;
}
},
and in the template I use
并在我使用的模板中
{{> quickForm collection="Comments" id="insertCommentForm" type="insert" post=this template="bootstrap3-inline" label-class="sr-only"}}
but post is undefined
so I get the error Uncaught TypeError: Cannot read property '_id' of undefined
.
但是post是未定义的所以我得到错误Uncaught TypeError:无法读取未定义的属性'_id'。
1 个解决方案