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 新婚祝福语大全简短经典