【发布时间】:2015-02-17 16:12:48
【问题描述】:
有人可以解释您如何使用 Worklight 6.2 链接适配器调用吗?
我目前正在使用 Worklight 开发一个混合移动应用程序,我遇到的问题是我需要对特定 Worklight 适配器进行 x 次调用,堆栈中的最后一个调用将始终是到不同的 Worklight 适配器。每个适配器调用都需要等待上一次调用的结果才能启动。
我可以将所有调用放入一个堆栈中,然后依次调用每个调用,但它们似乎没有在下一个开始之前等待前一个完成?
我目前的代码如下:
// Following line is executed in a loop to build the call stack
defCollection.push(sendUpdate(data));
// Following code executes the call stack
var deferred = $.Deferred();
var promise = deferred.promise();
$.each(defCollection, function(index, sndUpd) {
WL.Logger.info("EXECUTING :: " + index);
promise = promise.pipe(function() {return sndUpd;});
});
deferred.resolve();
// This is the Worklight adapter call
function sendUpdate(data){
var params = data;
var invocationData = {
adapter : "live",
procedure : "update",
parameters : [params],
compressResponse : true
};
WL.Client.invokeProcedure(invocationData, {
onSuccess : updateSuccess,
onFailure : updateFailure
});
}
我知道 .pipe 已被弃用,但目前,这是我设法让调用以正确的顺序执行的最接近的方法。
【问题讨论】:
标签: javascript ibm-mobilefirst worklight-adapters