return 属性的服务器方法无法正常工作 Meteor JavaScript

Server method to return attribute not working properly Meteor JavaScript

我正在尝试调用服务器方法 return 无论是否存在隐藏属性。属性 return 在终端控制台中正确,但在客户端不正确 return(return 未定义)。我要 return 的属性是 tireMarkup.

这是我的方法调用:

var currentUserId = this._id;

    Meteor.call('checkMarkup', currentUserId, function(tireMarkupExists) {
        console.log(tireMarkupExists) //returns undefined
        if(!tireMarkupExists) {
            alert('Please enter a tire markup greater than 1 for the customer');
            alert(tireMarkupExists) //returns undefined
        }

这是我的服务器方法:

Meteor.methods({
    'checkMarkup': function(currentUserId, tireMarkupExists) {
        console.log('user? ' + currentUserId); //returns the correct user
        a = Meteor.users.findOne(currentUserId); 
        console.log(a.tireMarkup); //returns the integer value correctly
        if (a.tireMarkup & a.tireMarkup > 1) {
            return (tireMarkupExists);
        }
      }
    });

有什么想法吗?我认为问题与我传递 currentUserIdtireMarkupExists 参数的方式有关。

为什么不 return true/false 结果值,像这样。

将您的服务器方法更改为此。

Meteor.methods({
    'checkMarkup': function(currentUserId) {
        console.log('user? ' + currentUserId); //returns the correct user
        a = Meteor.users.findOne(currentUserId); 
        console.log(a.tireMarkup); //returns the integer value correctly
        if (a.tireMarkup & a.tireMarkup > 1) {
            return true;
        }else{
             return false;
        }
      }
    });

并像这样使用Meteor.call

Meteor.call('checkMarkup', currentUserId, function(error,result) {
        if(!error){
          if(result === true){
             console.log("tireMarkupExists");
          }else{
             cosnole.log("tireMarkupExists dont exist")
          }  
         }else{
            console.log("Opss an error : " error.reason)
         }
        }