javascript – 未找到Meteor验证的方法

前端之家收集整理的这篇文章主要介绍了javascript – 未找到Meteor验证的方法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在将我的Meteor应用程序从Meteor 1.2迁移到Meteor 1.3并按照 http://guide.meteor.com/methods.html#validated-method上的指南创建一个经过验证的方法.

当我调用方法时,我认为客户端模拟正在发生,因为我可以注销到控制台,但总是会出现错误方法’…’未找到.

/imports/ui/pages/register.js

import {Meteor} from 'meteor/meteor';
import {Template} from 'meteor/templating';
import {FlowRouter} from 'meteor/kadira:flow-router';

// Methods
import {createAccount} from '/imports/api/accounts/methods.js';

// HTML
import './register.html';

Template.Register_page.events({
  'submit form': function(event) {
    event.preventDefault();

    var user = {
      email: $('#email').val(),password: $('#password').val(),profile: {
        firstName: $('#firstName').val(),lastName: $('#lastName').val()
      }
    };

    createAccount.call(user,function(err) {
      if (err) {
        console.error(err);
      } else {
        console.log('User successfully registered');
        FlowRouter.go('Dashboard');
      }
    });
  }
});

/imports/api/accounts/methods.js

import {Meteor} from 'meteor/meteor';
import {ValidatedMethod} from 'meteor/mdg:validated-method';
import {SimpleSchema} from 'meteor/aldeed:simple-schema';
import {Accounts} from 'meteor/accounts-base';

export const createAccount = new ValidatedMethod({
  name: 'createAccount',validate: new SimpleSchema({
    email: { type: String },password: { type: String },profile: { type: Object },"profile.firstName": { type: String },"profile.lastName": { type: String }
  }).validator(),run(user) {
    console.log(user);
    Accounts.createUser(user);
  },});

客户控制台

Object {email: "test@mailinator.com",password: "testPassw0rd",profile: Object}    methods.js:18
errorClass {error: 404,reason: "Method 'createAccount' not found",details: undefined,message: "Method 'createAccount' not found [404]",errorType: "Meteor.Error"}    register.js:28

解决方法

我认为这不起作用的原因是因为我没有在启动时初始化服务器上​​的javascript.

添加以下内容解决了以下问题:

/imports/startup/server/index.js

import './register-api.js';

/imports/startup/server/register-api.js

import '/imports/api/accounts/methods.js';

猜你在找的JavaScript相关文章