Javascript Meteor.call回调未执行,它';如果我不';我不去捡东西
为什么我要写这个:Javascript Meteor.call回调未执行,它';如果我不';我不去捡东西,javascript,meteor,meteor-methods,Javascript,Meteor,Meteor Methods,为什么我要写这个: /client/Items.js Template.Items.onCreated(function() { console.log('Methor.call'); Meteor.call('Items.findAll', function (err, resp) { console.log('Methor.call callback'); // Here I will use resp expecting it contains the respon
/client/Items.js
Template.Items.onCreated(function() {
console.log('Methor.call');
Meteor.call('Items.findAll', function (err, resp) {
console.log('Methor.call callback');
// Here I will use resp expecting it contains the response
// returned by the method
// ...
return;
});
return;
});
Meteor.methods({
'Items.findAll': function () {
return Items.find({});
}
});
/ItemsMethods.js
Template.Items.onCreated(function() {
console.log('Methor.call');
Meteor.call('Items.findAll', function (err, resp) {
console.log('Methor.call callback');
// Here I will use resp expecting it contains the response
// returned by the method
// ...
return;
});
return;
});
Meteor.methods({
'Items.findAll': function () {
return Items.find({});
}
});
回调被悄悄忽略,即它没有执行,我没有收到任何错误
注意,如果我替换这个返回Items.find({})使用此返回Items.find({}).fetch()代码>所有工作正常。项。查找({})代码>返回一个游标,该游标是指向检索到的数据的指针
如果使用Items.find({}).fetch()代码>返回的是一个对象数组。如果在中返回游标,则不会调用回调,因为游标不可序列化。根据状态,Meteor方法应该返回一个可启用的值或抛出一个异常
实际上,有一个更详细地描述了这个问题的示例。感谢您的澄清。我仍然不明白为什么在第一种情况下,Meteor.call
的回调没有执行?它与方法返回的数据类型有关吗?谢谢。现在我明白了。我希望将来会为这些情况抛出一个异常(至少是服务器端)。