meteor Meteor.call 的基础知识
例子
Meteor.call(name, [arg1, arg2...], [asyncCallback])
(1)nameString
(2)要调用的方法名称
(3)arg1,arg2...EJSON-ableObject[Optional]
(4)asyncCallbackFunction[Optional]
一方面,您可以这样做:(通过Sessionvariable,或通过ReactiveVar)
var syncCall = Meteor.call("mymethod") //同步通话这意味着如果你做这样的事情,服务器端你会做:
Meteor.methods({
mymethod: function() {
let asyncToSync = Meteor.wrapAsync(asynchronousCall);
//用结果做点什么;
return asyncToSync;
}
});另一方面,有时您会希望通过回调的结果保留它?
客户端:
Meteor.call("mymethod", argumentObjectorString, function (error, result) {
if (error) Session.set("result", error);
else Session.set("result",result);
}
Session.get("result") -> will contain the result or the error;
//会话变量带有一个跟踪器,每当会话变量设置新值时就会触发。\使用ReactiveVar的相同行为服务器端
Meteor.methods({
mymethod: function(ObjectorString) {
if (true) {
return true;
} else {
throw new Meteor.Error("TitleOfError", "ReasonAndMessageOfError"); //这将出现在Meteor.call的错误参数中
}
}
});这里的目的是展示Meteor提出了多种方式来在客户端和服务器之间进行通信。
热门推荐
10 结婚多层蛋糕祝福语简短
11 结婚祝福语简短精辟 兄弟
12 婚礼祝福语简短精辟的
13 周末思念祝福语大全简短
14 年末祝福语简短的文案
15 给表弟的祝福语简短
16 离别简短的祝福语大全
17 给长辈祝福语简短大全
18 上嫂子生日祝福语简短