我singlePost
postId
。在每个singlePost
中,我列出了评论。
Autoform征求意见:
{{#autoForm id="updateCommentArray" type="update-pushArray" collection=Collections.Posts doc=commentDoc scope="comment" template="semanticUI"}}
{{> afQuickField name="content"}}
<div class="form-group">
<button type="submit" class="ui positive button">Submit</button>
<button type="reset" class="ui negative button">Reset</button>
</div>
{{/autoForm}}
Autoform提供的是使用范围将新数组附加到指定字段。例如,当我使用范围comment.0.reply
时,该回复将附加到第一个注释数组。当我使用范围comment.1.reply
时,该回复将附加到第二个注释数组。等
如何让它动态化?我想的是使用commentId
,但是如何使用?
谢谢
答案 0 :(得分:0)
我认为它的工作原理如下:
范围定义表单添加的文档中的哪个数组。 doc 是表单应将数据添加到范围的文档。
例如(我没有对此进行测试,但它与我使用的代码类似):
<强>的javascript:强>
CommentsSchema = new SimpleSchema({
comment:{
type:String,
autoform:{
rows: 2
}
}
});
PostSchema = new SimpleSchema ({
content:{
type:String,
autoform: {
rows: 2
}
},
comments:{
type:[CommentsSchema]
}
});
<强>模板:强>
{{#each posts}}
{{#autoForm id=this._id type="update-pushArray" collection='Posts' doc=this scope="comment" template="semanticUI"}}
{{> afQuickField name="content"}}
<div class="form-group">
<button type="submit" class="ui positive button">Submit</button>
<button type="reset" class="ui negative button">Reset</button>
</div>
{{/autoForm}}
{{/each}}