我收到此错误:
Object <object> has no method apply
调用此函数时
var fb = new Facebook(Meteor.user().services.facebook.accessToken);
data =Meteor.wrapAsync(fb.query("/search?q=" + keywords + "&type=page&fields=name,category,can_post,likes,link,location,emails,phone"));
on server side.
更新: 尝试之后:
var fb = new Facebook(Meteor.user().services.facebook.accessToken);
var fbQuerySync = Meteor.wrapAsync(fb.query, fb);
var data = fbQuerySync("/search?q=" + keywords + "&type=page&fields=name,category,can_post,likes,link,location,emails,phone");
我收到此错误
Error inside the Async.runSync: Property 'function (/* arguments */) { // 99
W20150402-21:30:07.620(0)? (STDERR) var args = _.toArray(arguments); // 100
W20150402-21:30:07.620(0)? (STDERR) // 101
W20150402-21:30:07.620(0)? (STDERR) var runWithEnvironment = function () { // 102
W20150402-21:30:07.620(0)? (STDERR) var savedValues = Fiber.current._meteor_dynamics; // 103
W20150402-21:30:07.620(0)? (STDERR) try { // 104
W20150402-21:30:07.620(0)? (STDERR) // Need to clone boundValues in case two fibers invoke this // 105
W20150402-21:30:07.620(0)? (STDERR) // function at the same time // 106
W20150402-21:30:07.621(0)? (STDERR) Fiber.current._meteor_dynamics = _.clone(boundValues); // 107
W20150402-21:30:07.621(0)? (STDERR) var ret = func.apply(_this, args); // 108
W20150402-21:30:07.621(0)? (STDERR) } catch (e) { // 109
W20150402-21:30:07.621(0)? (STDERR) // note: callback-hook currently relies on the fact that if onException // 110
W20150402-21:30:07.621(0)? (STDERR) // throws and you were originally calling the wrapped callback from // 111
W20150402-21:30:07.621(0)? (STDERR) // within a Fiber, the wrapped call throws. // 112
W20150402-21:30:07.622(0)? (STDERR) onException(e); // 113
W20150402-21:30:07.622(0)? (STDERR) } finally { // 114
W20150402-21:30:07.622(0)? (STDERR) Fiber.current._meteor_dynamics = savedValues; // 115
W20150402-21:30:07.622(0)? (STDERR) } // 116
W20150402-21:30:07.622(0)? (STDERR) return ret; // 117
W20150402-21:30:07.622(0)? (STDERR) }; // 118
W20150402-21:30:07.623(0)? (STDERR) // 119
W20150402-21:30:07.623(0)? (STDERR) if (Fiber.current) // 120
W20150402-21:30:07.623(0)? (STDERR) return runWithEnvironment(); // 121
W20150402-21:30:07.623(0)? (STDERR) Fiber(runWithEnvironment).run(); // 122
OUPS: 该方法已经同步,这似乎是另一段代码:
Facebook.prototype.query = function(query, method) {
var self = this;
var method = (typeof method === 'undefined') ? 'get' : method;
var data = Meteor.sync(function(done) {
self.fb[method](query, function(err, res) {
done(null, res);
});
});
return data.result;
}
答案 0 :(得分:1)
试试这个:
var fb = new Facebook(Meteor.user().services.facebook.accessToken);
var fbQuerySync = Meteor.wrapAsync(fb.query, fb);
var data = fbQuerySync("/search?q=" + keywords + "&type=page&fields=name,category,can_post,likes,link,location,emails,phone");
您的代码的问题在于您将错误的参数传递给Meteor.wrapAsync
,如果要将传递的函数用作方法,则期望函数和最终上下文。
您获得的结果是可以在Meteor上下文中使用的同步函数。