如何将JS数组添加到Meteor自动表单条目中

How to add JS array to Meteor autoform entry

本文关键字:表单 Meteor JS 数组 添加      更新时间:2023-09-26

我使用的是Meteor 1.1.0和Alded:Autoform,我需要在提交期间(或之前)将模板JS文件中生成的字符串数组中的值放入[string]类型的文档条目中。我该怎么做?

解决方案是在Autoform.hooks中添加一个before:hook,其中包含一个insert:函数,该函数将修改文档条目(要使其工作,必须在架构中定义参数)。示例:

AutoForm.hooks({
    'add-form': {
        before:{
            insert:function(doc){
                doc.fileId = '1234; // doc is the data from the form. 
                return doc; // .fileId is the element we try to modify
            }
        }  
    }
});