2013-12-18 49 views
2

我新来的流星,我想做一个使用流星的注册表格,我卡在findOnesubscribe/publish。 这是我的`collection.js常见:流星订阅undefined

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将返回,如果电子邮件/身份证/电话已存在集合中:

Identity in Customer 
Email in User_Customer 
Phone in User_Customer 

和问题的过程无法继续进入第二认购后,我做的断点与我的铬,custundefined值。 请帮帮我,该如何解决这个功能?

感谢

回答

0

你需要调用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;     
} 
+0

感谢答案,我试试您的解决方案,但它仍然未定义 – yozawiratama

1

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

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