【问题标题】:Meteor validated method not found未找到流星验证方法
【发布时间】:2016-08-07 03:19:04
【问题描述】:

我正在将 Meteor 应用程序从 Meteor 1.2 迁移到 Meteor 1.3,并按照 http://guide.meteor.com/methods.html#validated-method 上的指南创建经过验证的方法。

当我调用该方法时,我相信客户端模拟正在发生,因为我可以注销到控制台,但这之后总是出现错误 Method '...' not found

/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 meteor meteor-accounts


    【解决方案1】:

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

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

    /imports/startup/server/index.js

    import './register-api.js';
    

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

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

    【讨论】:

      猜你喜欢
      • 2016-11-08
      • 2014-06-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-20
      • 1970-01-01
      相关资源
      最近更新 更多