Meteor 如何调用 Meteor.methods() 中定义的方法? [英] Meteor how to call a method defined in Meteor.methods()?
本文介绍了Meteor 如何调用 Meteor.methods() 中定义的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在为 Meteor 服务器分配方法,如下所示:
I am assigning methods to a Meteor server like so:
在 bootstrap.js 中
In bootstrap.js
Meteor.startup(function () {
Meteor.methods({
foo: function () {
return 1;
},
bar: function () {
// QUESTION: HOW TO CALL Meteor.methods.foo
return 1 + foo;
}
});
});
推荐答案
与调用 bar 的方式相同:Meteor.call("foo");
The same way you would call bar: Meteor.call("foo");
如果您在服务器上并且未指定回调,则该方法将同步运行.
If you are on the server and do not specify a callback the method will run synchronously.
Meteor.call 文档: http://docs.meteor.com/#meteor_call
这篇关于Meteor 如何调用 Meteor.methods() 中定义的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文