来自 Session.get() 的自动值

AutoValues from Session.get()

我在其他地方有一个简单的模式可以在 meteor 中使用 autoform。我的架构中的这个字段有问题。当我提交表单时,它什么也不做。如何通过 Session.get()?

在具有自动值的数组中设置和插入我的 id_master 的值
master_id: {
    type: [String],
    label: "id_master",
    autoValue: function(){
    if( this.isInsert ) {
        var x =Session.get('id_master'); 
        console.log(x);//returns the value of id_master
       return [x]
        }
    }, 
    autoform:{
        type: "hidden"
    }

},

我正在使用 autoForm :

{{> quickForm collection="Hitos" id="insertHitosForm" type="insert" class="new-hito-form"}}

我允许插入 :

Hitos.allow({
        insert: function(userId, doc){
            //you are allowed to insert Hitos if userid exist
            return !!userId;

        }
});

根据文档,您不需要,但是您是否尝试过使用 clean()

AutoForm.hooks({
  insertHitosForm: {
    onSubmit: function (doc) {
      Hitos.clean(doc);
      console.log("Hitos doc with auto values", doc);
      this.done();
      return false;
    }
  }
});

看起来这也是早些时候的一个问题。参考thispost

试试这样的方法是否也适合您。

AutoForm.hooks({
     insertHitosForm:{
        before: {
          insert: function(doc) {
               doc.master_id = [Session.get('active_project')]
               return doc;
               }
        }
   }
});