Validated-method触发并返回未定义的错误

时间:2017-05-01 11:38:42

标签: meteor

我尝试将mdg:validated-method实现为insert新集合,但是,我的代码返回undefined错误消息。 console.log(profileCandidate)run返回对象。它似乎停止在insert工作。

路径:imports/api/profileCandidate/methods.js

import SimpleSchema from 'simpl-schema';
import { ValidatedMethod } from 'meteor/mdg:validated-method';

import ProfileCandidate from './profileCandidate.js';

export const insertProfileCandidate = new ValidatedMethod({
  name: 'profileCandidate.insert',
  validate: new SimpleSchema({
    'firstName': { type: String },
  }).validator(),
  run(profileCandidate) {
    console.log("profileCandidate", profileCandidate);

    ProfileCandidate.insert({
      userId: Meteor.userId(),
      createdAt: new Date(),
      name: {
        first: profileCandidate.firstName,
      },
    });
  },
});

路径:imports/api/profileCandidate/profileCandidate.js

import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import { check } from 'meteor/check';
import SimpleSchema from 'simpl-schema';

export const ProfileCandidate = new Mongo.Collection('profileCandidate');

ProfileCandidate.schema = new SimpleSchema({
  userId: {
    type: String,
  },
  createdAt: {
    type: Date,
  },
  name: Object,
    'name.first': String,
});

ProfileCandidate.attachSchema(ProfileCandidate.schema);

1 个答案:

答案 0 :(得分:0)

事实证明该方法没有错误。错误在于我如何导入架构。我需要将import ProfileCandidate from './profileCandidate.js';更改为import { ProfileCandidate } from './profileCandidate.js';。如果有人能说明为什么你需要花括号,在这种情况下,我会很感激。