gpt4 book ai didi

javascript - 如何在 Meteor 中使用 AutoForm 添加关系或引用?

转载 作者:行者123 更新时间:2023-11-30 17:08:18 26 4
gpt4 key购买 nike

我使用 meteor-autoform 在集合中插入文档。我的 Items 有一个字段 groupId。我如何在提交商品表单时插入此组 ID。

<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 的字段,但我不希望用户看到该字段。

如何在“幕后”设置 groupId

最佳答案

为此,您需要 a hook .您还需要为表单设置一个 ID,比方说 addItemForm

//Anywhere in your client code
Autoform.hooks({
addItemForm : {
onSubmit : function(doc) {
doc.groupId = /*Get the group id*/;
this.done(); //We've finished
return true; //Let autoForm do his default job now
}
}
});

关于javascript - 如何在 Meteor 中使用 AutoForm 添加关系或引用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27522537/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com