Meteor.call 回调未执行,如果我不进行提取,它会被静默忽略
Meteor.call callback is not executed and it's silently ignored if I don't do a fetch
为什么我要这样写:
/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;
});
/ItemsMethods.js
Meteor.methods({
'Items.findAll': function () {
return Items.find({});
}
});
回调被默默地忽略了,即它没有被执行而且我没有收到任何错误?
请注意,如果我将此 return Items.find({});
替换为此 return Items.find({}).fetch();
,一切都会按预期进行。
Items.find({});
return 一种游标,它是一种指向检索到的数据的指针。
如果您使用 Items.find({}).fetch();
,您将 return 创建一个对象数组。
如果您在 Meteor method, the callback will not be called, because cursors are not serialisable. As the documentation states, Meteor methods should return an EJSON 可用值中返回游标或抛出异常。
实际上有一个feature request on GitHub,它更详细地描述了这个问题。
为什么我要这样写:
/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;
});
/ItemsMethods.js
Meteor.methods({
'Items.findAll': function () {
return Items.find({});
}
});
回调被默默地忽略了,即它没有被执行而且我没有收到任何错误?
请注意,如果我将此 return Items.find({});
替换为此 return Items.find({}).fetch();
,一切都会按预期进行。
Items.find({});
return 一种游标,它是一种指向检索到的数据的指针。
如果您使用 Items.find({}).fetch();
,您将 return 创建一个对象数组。
如果您在 Meteor method, the callback will not be called, because cursors are not serialisable. As the documentation states, Meteor methods should return an EJSON 可用值中返回游标或抛出异常。
实际上有一个feature request on GitHub,它更详细地描述了这个问题。