簡體   English   中英

自動套用欄位

[英]AutoForm fields

我正在使用包aldeed:autoform創建一個表單

所以這是我的代碼

CompanyData = new Mongo.Collection('companyData');
CompanyData.attachSchema(new SimpleSchema({
    allFields: {
        type: String,
        allowedValues: ['title', 'logo', 'url'],
        autoform: {
            type: "selectize"
        }
    },
    title:{
        type:'String',
        label:'Name',
        unique:true,
        max:100
    },

    logo:{
        type:'String',
        label:'Logo',
        optional:true
    }
}));

這就是我所需要的

  1. 當用戶將數據插入集合中時,我想添加一個名為“ createdBy”的字段,其值將為userId。

  2. 當用戶更新數據時,我想添加一個名為“ updatedBy”的字段,其值將為userId。

現在,當用戶更新數據時,“ createdBy”字段不應更新。 但是“ updatedBy”字段應該更新。

是的,當顯示表單字段時,將不顯示createdBy和updateedBy字段。

任何幫助

在meteor-collection2自述文件( https://github.com/aldeed/meteor-collection2#autovalue )上有明確的文檔。

  // Force value to be current date (on server) upon insert // and prevent updates thereafter. createdAt: { type: Date, autoValue: function() { if (this.isInsert) { return new Date; } else if (this.isUpsert) { return {$setOnInsert: new Date}; } else { this.unset(); } } }, // Force value to be current date (on server) upon update // and don't allow it to be set upon insert. updatedAt: { type: Date, autoValue: function() { if (this.isUpdate) { return new Date(); } }, denyInsert: true, optional: true } 

在本文檔的示例中,使用createdAt和updatedAt。 您只需要更改這些內容即可引用用戶ID。

  createdBy: {
    type: String,
    autoValue: function() {
      if (this.isInsert) {
        return this.userId;
      } else if (this.isUpsert) {
        return {$setOnInsert: this.userId};
      } else {
        this.unset();
      }
    }
  },
  updatedBy: {
    type: String,
    autoValue: function() {
      if (this.isUpdate) {
        return this.userId;
      }
    },
    denyInsert: true,
    optional: true
  }

您可以將其添加到每個字段中,以防止其顯示在自動表單/快速表單中:

autoform: {
  omit: true
}

或者,您可以在表單中使用omitFields="createdBy,updatedBy"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM