流星路由器与流星呼叫
Meteor Router with Meteor call
我无法通过路由器上的 Meteor.call 验证用户。只有 return "undefined" pr
"Exception in delivering result of invoking 'verifyUserRole':
TypeError: undefined is not a function"
Router.route("/admin", function(){
Meteor.call("verifyUserRole", function(error, result){
if(result){
this.render('adminDashboard');
this.layout("adminLayout");
} else {
this.render('adminLogin');
}
})
});
Meteor.methods({
"verifyUserRole" : function(){
if(this.userId){
var user = Meteor.user();
var role = user.profile.role;
if(role == "admin"){
return true;
} else {
Session.set("adminLoginError", "Restrict Area");
return false;
}
}
}});
this
的值是指您的内部函数而不是外部函数。尝试以下操作:
Router.route("/admin", function(){
var self = this;
Meteor.call("verifyUserRole", function(error, result){
if(result){
self.render('adminDashboard');
self.layout("adminLayout");
} else {
self.render('adminLogin');
}
});
});
我无法通过路由器上的 Meteor.call 验证用户。只有 return "undefined" pr
"Exception in delivering result of invoking 'verifyUserRole': TypeError: undefined is not a function"
Router.route("/admin", function(){
Meteor.call("verifyUserRole", function(error, result){
if(result){
this.render('adminDashboard');
this.layout("adminLayout");
} else {
this.render('adminLogin');
}
})
});
Meteor.methods({
"verifyUserRole" : function(){
if(this.userId){
var user = Meteor.user();
var role = user.profile.role;
if(role == "admin"){
return true;
} else {
Session.set("adminLoginError", "Restrict Area");
return false;
}
}
}});
this
的值是指您的内部函数而不是外部函数。尝试以下操作:
Router.route("/admin", function(){
var self = this;
Meteor.call("verifyUserRole", function(error, result){
if(result){
self.render('adminDashboard');
self.layout("adminLayout");
} else {
self.render('adminLogin');
}
});
});