简体   繁体   English

如何将JS数组添加到流星自动表单输入

[英]How to add JS array to Meteor autoform entry

I am using Meteor 1.1.0 and Aldeed:Autoform and I need to put values from a string array that is generated in the template's JS file into a document entry of type [String] during (or before) submit. 我正在使用Meteor 1.1.0和Aldeed:Autoform,并且需要在提交之前(或之前)将模板JS文件中生成的字符串数组中的值放入[String]类型的文档条目中。 How can I do that? 我怎样才能做到这一点?

The solution is to add a before: hook in Autoform.hooks with an insert: function in it, which would modify the document entries ( for this to work the parameter must be defined in the schema ). 解决方案是在Autoform.hooks中添加一个before:钩子,并在其中插入一个insert:函数,这将修改文档条目(为此,必须在模式中定义参数)。 Example: 例:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM