【问题标题】:Meteor aldeed/meteor-collection2 autoValue throwing errorMeteor aldeed/meteor-collection2 autoValue 抛出错误
【发布时间】:2016-12-20 00:21:41
【问题描述】:

我正在尝试在我的架构中使用 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
            }
       });
    }
});

它不起作用。我收到一条错误消息

发布是必需的[验证错误]

我做错了吗?我需要将已发布字段设为可选吗?

我尝试通过为张贴提供默认值来更改插入方法:new Date()。也没有工作。请帮忙。

【问题讨论】:

    标签: meteor meteor-collection2 simple-schema


    【解决方案1】:

    通过使用 { clean : true, filter : false } 调用验证器来修复它

    【讨论】:

      猜你喜欢
      • 2014-01-27
      • 2016-10-08
      • 2017-05-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-23
      • 2016-03-28
      • 1970-01-01
      相关资源
      最近更新 更多