如何在使用postId时将meteor-autoform链接到注释
我试过了
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都是没有定义的。
编辑
我就是这样用的:
<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"}}但是post是undefined,所以我得到了错误Uncaught TypeError: Cannot read property '_id' of undefined。
发布于 2015-07-05 13:41:30
相反,使用您的
{{> quickForm collection=“注释”“id="insertCommentForm”type=“插入”}“
试试看
{{> quickForm collection=“注释”“id="insertCommentForm”type=“插入”postId=_id}“
然后尝试访问助手内部的这个值
Template.instance().data.postId
还可以将整个post对象发送到子模板,如下所示
{{> quickForm collection=“注释”“id="insertCommentForm”type=“插入”post=this}“
然后可以通过以下方式完全访问该集合文档
(例如)
Template.instance().data.post._id
这是一个通过模板访问数据的小示例。
http://meteorpad.com/pad/Ke9DJnbvtsqjSHJy2/SimpleDataGivenThroughTemplates
https://stackoverflow.com/questions/31229713
复制相似问题