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提出了多种方式来在客户端和服务器之间进行通信。
热门推荐
1 训练狗狗基础
2 怎么训练狗狗笑
3 怎么训练狗狗卧下
4 上海狗狗训练基地
5 训练狗狗排便
6 狗狗基础训练
8 如何训练狗狗装死
9 狗狗站姿训练
10 狗狗训练用品
11 训练狗狗吧
12 狗狗要怎么训练
13 怎么训练狗狗玩球
14 训练狗狗唤回
15 狗狗训练躺下
16 狗狗训练指令
17 狗狗的训练技巧
18 狗狗不好训练