如何在Meteor中使用AutoForm添加关系或引用? [英] How to add a relationship or reference with AutoForm in Meteor?

查看:123
本文介绍了如何在Meteor中使用AutoForm添加关系或引用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用meteor-autoform将文档插入集合中.我的Items有一个字段groupId.提交项目表单时,如何插入此组ID.

I use meteor-autoform to insert documents in a collection. My Items has a field groupId. How can I insert this group id when I'm submitting my item form.

<template name="itemForm">
  {{#autoForm type="insert" collection=Collections.Items}}
    {{> afQuickField name="name"}}
    <div class="form-group">
      <button type="submit" class="btn btn-primary">Add item</button>
      <button type="reset" class="btn btn-default">Reset Form</button>
    </div>
  {{/autoForm}}
</template>

我可以创建另一个包含组ID的字段,但我不希望用户看到此字段.

I could create another field containing my group id but I don't want the user to see this field.

如何将groupId设置在幕后"?

推荐答案

我认为一个解决方案不是向用户显示此选项.您还需要在该字段中添加optional:true,因此提交表单时该字段仍然有效.

I think one solution is not this display this option to user. You need to also add optional:true to the field, so it will still be valid when you submit the form.

然后使用挂钩,您应该可以添加所需的任何其他数据

Then using the hooks, you should be able to add any other data you want

可以使用文档通过自动表单挂钩

我通常会修改before insert

AutoForm.hooks({
  myFormId: {
    before: {
      insert: function(doc, template) {
        //modify the document here
      }
    }
})

这篇关于如何在Meteor中使用AutoForm添加关系或引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆