代码之家  ›  专栏  ›  技术社区  ›  ASX

在函数参数未定义的情况下调用Meteor Async ValidatedMethod

  •  1
  • ASX  · 技术社区  · 7 年前
    someMethod = new ValidatedMethod({
        name: 'someMethodName',
        validate: new SimpleSchema({
            subId: {type: String, min:1},
            planId: {type: String}        
        }).validator(),
        async run(params){
            try{
                         //params is undefined
            } 
    
        }
    });
    

    async run(params) 原因 params 成为 undefined Global async 工作正常(除了我不能再在方法体中使用wait)。 ValidatedMethod

    注1: 我像这样从客户机调用该方法——如果我尝试使用正则表达式,就会得到相同的结果 Meteor.methods({}) 释义我使用 Meteor.apply 来自客户

    ClientHelpers.callWithPromise = function(methodName, methodArgs){
      //methodArgs must be an array
      return new Promise(function(resolve, reject){
        Meteor.apply(methodName, methodArgs, {wait:true}, function(error, result){
          if (error){
            reject(error);
          } 
          console.log(result);
          resolve(result);
        });
      });
    }
    

    然后,拜访客户(我确定 paramsObject 是正确的):

    var myResult = await ClientHelpers.callWithPromise('someMethodName', [paramsObject]);
    

    注2: 准对象 通过DDP,在调试会话中:

      // Sends the DDP stringification of the given message object
      _send(obj) {
        this._stream.send(DDPCommon.stringifyDDP(obj));
      }
    

    0 回复  |  直到 7 年前