[英]Callback in client for Meteor method call returning undefined
So I'm calling a method from the client that has a callback: 因此,我从具有回调的客户端调用一个方法:
Meteor.call("readHeaders", Meteor.user().emails[0].address+'/'+Session.get("file1"),
function(err,result){
console.log(result);
});
and here is the method that's being called: 这是被调用的方法:
readHeaders: function(fileName){
var nodeFS = Meteor.npmRequire('node-fs');
nodeFS.readFile("somepath/"+fileName,'utf8', function read(err, data){
if (err) {
throw err;
}
var headers = [data.slice(0,data.indexOf('\n')).split(",")];
return headers;
});
}
The correct result gets printed on the server, but on the client it returns undefined. 正确的结果将显示在服务器上,但在客户端上将返回未定义。 Any suggestions?
有什么建议么?
I'm guessing your method call and callback are fine, but your method itself is probably not returning what you're expecting. 我猜您的方法调用和回调很好,但是您的方法本身可能未返回您期望的结果。 Add a
console.log(headers)
before the return headers
line and make sure it's an object. 在
return headers
行之前添加console.log(headers)
并确保它是一个对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.