我有以下内容(来自Tridion PowerTools),当某些 JavaScript 运行时,它会从 CoreService 获取用户名。
JavaScript(安圭拉):
PowerTools.Popups.Example.prototype._onbtnGetUserInfoClicked = function () {
var onSuccess = Function.getDelegate(this, this._handleUserInfo);
var onFailure = null;
var context = null;
//call function
PowerTools.Model.Services.Example.GetUserInfo(onSuccess, onFailure,
context, false);
};
// Delegate function "onSuccess"
PowerTools.Popups.Example.prototype._handleUserInfo = function (response) {
var p = this.properties;
$j("#lblUserInfo").text(response.UserName);
};
CoreService 端:(C# .svc)
[OperationContract, WebGet(ResponseFormat = WebMessageFormat.Json)]
public ExampleData GetUserInfo()
{
var coreService = Client.GetCoreService();
_exampleData = new ExampleData()
{
UserName = coreService.GetCurrentUser().Title
};
return _exampleData;
}
这会发送一个异步调用:
PowerTools.Model.Services.Example.GetUserInfo(onSuccess, onFailure, context, false)
而这分配了一个不同的函数来处理响应:
Function.getDelegate(this, this._handleUserInfo)
但是 onSuccess、onFailure、context 和 Boolean 是从哪里来的:PowerTools.Model.Services.Example.GetUserInfo(onSuccess, onFailure, context, false)
?
此四参数签名与服务代码中的无参数 GetUserInfo() 不匹配。为什么那个顺序和这四个?