Meteor 如何在将quickform存储到数据库之前向其添加额外属性?

Meteor 如何在将quickform存储到数据库之前向其添加额外属性?,meteor,meteor-autoform,Meteor,Meteor Autoform,我有一个全局变量,用于存储用户上传图像的url。 在将该变量添加到数据库之前,如何将其作为属性添加到文档中 这是我的密码 Meteor.methods({ submitPost: function (app) { // Console.log('new App:', app); check(app, { title: String, description: String, categ

我有一个全局变量,用于存储用户上传图像的url。 在将该变量添加到数据库之前,如何将其作为属性添加到文档中

这是我的密码

Meteor.methods({
    submitPost: function (app) {
        // Console.log('new App:', app);
        check(app, {
            title: String,
            description: String,
            category: String,
            price: Number
        });
        Products.insert(app);
    }

});
我想在“app”中添加全局变量,然后再将其插入产品集合中

previewImage: {
    type: String,
    autoValue: function(){
      return PIurl;
    },
    autoform: {
      type: "hidden"
    }
  },
  createdAt:{
    type: String,
    autoValue: function(){
      return new Date();
    },
    autoform: {
      type: "hidden"
    }
  }
}));
我该怎么做

这是我在收藏中添加的内容

previewImage: {
    type: String,
    autoValue: function(){
      return PIurl;
    },
    autoform: {
      type: "hidden"
    }
  },
  createdAt:{
    type: String,
    autoValue: function(){
      return new Date();
    },
    autoform: {
      type: "hidden"
    }
  }
}));

添加上述代码后,单击submit时不会发生任何事情,表单不再存储在数据库中

有两种方法可以实现这一点,第一种是使用AutoForm.hooks
onSubmit
hook。另一种方法是使用对象属性
autoValue
将其添加到模式中:

 Schema.something = new SimpleSchema({
     category: {
       type: String,
       autoValue: function () {
        return "foo";
       }
     },

我添加了你的解决方案并编辑了我的问题,添加后,当我单击“提交”时,什么都没有发生,现在正在检查自动表单挂钩:)你在使用meteor自动表单吗?是的,我在使用它,表单在不添加自动值字段的情况下运行良好:)感谢它的工作,我将日期类型设置为字符串,它应该是日期类型,当我更改它时,成功了,我接受了你的回答,谢谢:)