【问题标题】:Meteor subscribe undefinedMeteor 订阅 undefined
【发布时间】:2016-07-08 09:39:57
【问题描述】:

我是流星的新手,我想用流星制作注册表,我卡在findOnesubscribe/publish。 这是我的 `collection.js common :

User_Customer = new Meteor.Collection("USER_CUSTOMER");
Customer = new Meteor.Collection("CUSTOMER");

这是我的publish.js/server

Meteor.publish("CUSTOMER", function() {
    return Customer.find();
});

Meteor.publish("USER_CUSTOMER", function() {
    return User_Customer.find();
});

这是我订阅和 findOne /client 的功能:

function isAvailableForUserRegister(email,identiy,phone){
    Meteor.subscribe("CUSTOMER", function(){
        var cust = null;
        cust = Customer.findOne({Identity: identiy});
        if(cust != null){
            Meteor.subscribe("USER_CUSTOMER", function(){
                var uc1 = null;
                uc1 = User_Customer.findOne({Email: email});
                if(uc1 != null){
                    var uc2 = null;
                    uc2 = User_Customer.findOne({Phone: phone});
                    if(uc2 != null)
                        return true
                    else
                        return false;
                }else return false;
            });
        }else return false;
    });
}

这个函数isAvailableForUserRegister将返回如果email/identity/phone已经存在于集合中:

Identity in Customer
Email in User_Customer
Phone in User_Customer

问题是进程不能继续进入第二个订阅,在我用我的 chrome 做断点之后,custundefined 值。 请帮助我,如何解决这个功能?

谢谢

【问题讨论】:

    标签: javascript meteor


    【解决方案1】:

    我认为是异步问题,订阅没有准备好,试试这个

    Meteor.subscribe("CUSTOMER").ready();
    Meteor.subscribe("USER_CUSTOMER").ready();

    【讨论】:

      【解决方案2】:

      您只需在客户端内调用一次Meteor.subscribe

      客户端代码:

      Meteor.subscribe("CUSTOMER");
      Meteor.subscribe("USER_CUSTOMER");
      
      function isAvailableForUserRegister(email,identiy,phone){
        var cust = Customer.findOne({Identity: identiy});
        if(cust === null) {
          return false;
        }
        var uc1 = User_Customer.findOne({$or: [
          {"Email": email}, 
          {"Phone": phone}
        ]);
        return uc1 !== null;                
      }
      

      【讨论】:

      • 感谢您的回答,我尝试了您的解决方案,但仍然未定义
      猜你喜欢
      • 2013-01-18
      • 2015-04-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-29
      • 2018-07-09
      • 2023-03-12
      • 1970-01-01
      相关资源
      最近更新 更多