[英]Meteor subscribe undefined
i new in meteor, I want to make a registration form use meteor, and i stuck in findOne
and subscribe/publish
. 我是流星的新手,我想使用流星制作一个注册表,因此我陷入了
findOne
并subscribe/publish
。 this is my `collection.js common : 这是我的`collection.js共同的:
User_Customer = new Meteor.Collection("USER_CUSTOMER");
Customer = new Meteor.Collection("CUSTOMER");
this is my publish.js
/server
: 这是我的
publish.js
/server
:
Meteor.publish("CUSTOMER", function() {
return Customer.find();
});
Meteor.publish("USER_CUSTOMER", function() {
return User_Customer.find();
});
and this is my function to subscribe and findOne /client
: 这是我的订阅和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;
});
}
this function isAvailableForUserRegister
will return if email/identity/phone already exist in collection : 如果集合中已经存在电子邮件/身份/电话,则此函数
isAvailableForUserRegister
将返回:
Identity in Customer
Email in User_Customer
Phone in User_Customer
and the problem is process not continue enter to second subscribe, after i do breakpoint with my chrome, cust
have undefined
value. 而问题是过程无法继续进入第二认购后,我做的断点与我的铬,
cust
有undefined
值。 please help me, how to solve this function? 请帮帮我,如何解决这个功能?
thanks 谢谢
I think it's a asynchronous problem, subscription is not ready, try this 我认为这是一个异步问题,订阅尚未准备就绪,请尝试一下
Meteor.subscribe("CUSTOMER").ready(); Meteor.subscribe("USER_CUSTOMER").ready();
You need to call Meteor.subscribe
only once inside the client. 您只需在客户端内部调用
Meteor.subscribe
一次。
Client code: 客户代码:
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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.