在Meteor中的autoform方法中传递额外的args

时间:2015-07-15 17:20:45

标签: javascript node.js meteor meteor-autoform

我使用我的quickform

插入文档
{{> quickForm id=id collection=collection type="method" meteormethod="createDoc"}}

但我也想在所有插入的文档上设置userId

我的模板中有变量userId,所以我想知道我是否可以做一些像

这样的事情
{{> quickForm id=id collection=collection type="method" meteormethod="createDoc" userId=userId}}

并在我的服务器方法中使用传递的变量?

1 个答案:

答案 0 :(得分:0)

您可以在autoform挂钩中添加其他参数:

HTML

{{> quickForm id="idForm" collection=collection type="method" meteormethod="createDoc"}}

JS

AutoForm.hooks({
        idForm: {
            before: {
                method: function(doc) {
                    doc.user = {}
                    doc.user._id = Meteor.user()._id;
                    doc.user.username = Meteor.user().username;
                    return doc;
                }               
            },
            onSuccess: function(formType, result) {             
                console.log(formType, result);
                this.resetForm();
            },
            onError: function(formType, error) {
                console.log(formType, error)
            }

            }
        }
    }); 

有关详细信息,请查看文档的此部分 Callbacks/Hooks