我使用包al契据: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
}
}));这就是我需要的
现在,当用户更新数据时,不应该更新“createdBy”字段。但是“updatedBy”字段应该更新。
是的,当显示表单字段时,将不显示createdBy和updatedBy字段。
任何帮助
发布于 2015-05-19 13:56:56
在流星收集2自述(https://github.com/aldeed/meteor-collection2#autovalue)上有关于这方面的明确文档。
// Force值为插入/时的当前日期(在服务器上),并防止此后进行更新。createdAt:{ type: Date,autoValue: function() { if (this.isInsert) {返回新日期;} else (this.isUpsert) {返回{$setOnInsert:新日期};}this.isUpsert{ this.unset();} },// Force值在更新//时为当前日期(在服务器上),并且不允许在插入时设置它。updatedAt:{ type: Date,autoValue: function() { if (this.isUpdate) {返回新日期();},denyInsert: true,可选: 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
}您可以将它添加到每个字段中,以防止它在autoforms/quickforms中显示:
autoform: {
omit: true
}也可以在表单中使用omitFields="createdBy,updatedBy"。
https://stackoverflow.com/questions/30325369
复制相似问题