我想在我的模式中使用autoValue
Posts.schema = new SimpleSchema({
title: { type: String },
description: { type: String },
posted: { type: Date,
autoValue: function (){
return new Date;
},
},
likes: { type: Number, defaultValue: 0, optional: true },
dislikes: { type: Number, defaultValue: 0, optional: true, },
author: { type: AuthorSchema },
votes: { type: [AuthorSchema], optional: true }
});
Posts.attachSchema(Posts.schema);
我在这里使用这个模式进行验证:
export const addPost = new ValidatedMethod({
name: 'Posts.addPost',
validate: Posts.schema.validator(),
run(post) {
if (!this.userId)
throw new Meteor.Error('403', 'You must be logged-in to reply');
Posts.simpleSchema().clean(post);
Posts.insert({
title: post.title,
description: post.description,
author: {
userId: this.userId,
vote: 0
}
});
}
});
它不工作。我得到一个错误信息
post是必需的[validation-error]
我做错了什么吗?我需要使张贴字段可选吗?
我试图通过为张贴提供默认值来更改插入方法:new Date()。也不管用。请帮助。
使用{clean: true, filter: false}调用validator修复