【发布时间】:2013-12-04 00:41:15
【问题描述】:
我在 Meteor 中遇到了一些我不理解的问题。我有这个方法,它接受一个查询,将它发送到亚马逊,然后在该函数的回调中我尝试返回结果。
Meteor.methods({
'search': function(query) {
var bookInfo;
if (Meteor.isServer) {
amazon.execute('ItemSearch', {
'SearchIndex': 'Books',
'Keywords': query,
'ResponseGroup': 'ItemAttributes'
}, function(results) {
bookInfo = results;
console.log(bookInfo);
return bookInfo;
});
}
}
});
但是当我在浏览器(chrome)的控制台中输入以下内容时:
Meteor.call('search', 'harry potter', function(error, response) {
console.log('response:', response);
});
我明白了:
undefined
response: undefined VM13464:3
我想我明白第一个 undefined 来自客户端上没有返回任何内容的方法,但回调似乎根本不起作用。
amazon.execute(...) 肯定会返回一些东西,因为返回上方的 console.log 确实记录了我正在寻找的信息。
任何想法出了什么问题以及如何解决它?
【问题讨论】:
标签: javascript asynchronous callback meteor undefined