如何在将快速表单存储到数据库之前向其添加额外的属性?

how to add extra attributes to the quickform before storing it in the database?

我有一个全局变量,用于存储用户上传图片的 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" 中添加全局变量,然后再将其插入产品 collection

我该怎么做?

这是我在 collection

中添加的内容
previewImage: {
    type: String,
    autoValue: function(){
      return PIurl;
    },
    autoform: {
      type: "hidden"
    }
  },
  createdAt:{
    type: String,
    autoValue: function(){
      return new Date();
    },
    autoform: {
      type: "hidden"
    }
  }
}));

添加上面的代码后,点击提交时没有任何反应,表单不再存储在数据库中

有两种方法可以实现这一点,第一种是使用 AutoForm.hooks onSubmit 钩子 autoform hooks。另一种方法是使用 autoValue 的对象属性将其添加到您的架构中:

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