Autoform推送数组的动态作用域(将回复附加到指定的评论id中)



我有singlePostpostId。在每个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,但如何?

谢谢

我认为它是这样的:

作用域定义表单要添加到文档中的哪个数组。文档是表单将数据添加到作用域的文档。

例如(我没有测试这个,但它与我使用的代码相似):

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}}

最新更新