简体   繁体   English

来自Session.get()的自动值

[英]AutoValues from Session.get()

I have a simple schema in other to use autoform in meteor . 我在其他autoform有一个简单的架构,可以在meteor使用autoform I am having problem with this field in my Schema. 我的架构中的此字段存在问题。 When I submit the form it does nothing. 当我提交表格时,它什么也不做。 How can I set and insert the value of my id_master in the array with autoValues through the Session.get() ? 如何通过Session.get()使用autoValues在数组中设置和插入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"
    }

},

I'm using autoForm : 我正在使用autoForm:

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

And I have allowed Inserting : 而且我允许插入:

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

        }
});

According to the documentation, you shouldn't need to, but have you tried using clean() ? 根据文档,您不需要,但是是否尝试使用clean()

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

Looks like this was an issue earlier as well. 看起来这也是一个较早的问题。 Refer to this post 参考这篇文章

Try if something like this would work for you as well. 尝试一下类似的方法是否也适合您。

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

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

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