【发布时间】:2016-01-22 12:27:01
【问题描述】:
大家好,我有来自三个独立 SharePoint 列表的三个异步调用,每个查询都有一个返回对象和数组的成功回调。我希望在所有三个成功回调返回后执行另一个函数。我不知道如何让它与 jQuery deferreds 一起工作。我的代码如下。请帮助我了解如何使用延迟来实现上述目标。
function managementMain() {
//From here I want to call the third function after executing
the managementQuery function.
outPutObj = managementQuery();
//Execute some third function with outPutObj:
third function(outPutObj);
}
function managementQuery() {
//CAML definition 1 here.
clContext.executeQueryAsync(Function.createDelegate(this, function () { var soObj = onSOQuerySucceeded(); }), Function.createDelegate(this, this.onQueryFailed));
//CAML definition 2 here.
clContext.executeQueryAsync(Function.createDelegate(this, function () { var poObj = onPOQuerySucceeded(); }), Function.createDelegate(this, this.onQueryFailed));
//CAML definition 3 here.
clContext.executeQueryAsync(Function.createDelegate(this, function () { var salesRepNamesList = onSalesRepNamesQuerySucceeded(); }), Function.createDelegate(this, this.onQueryFailed));
return {
soObj: soObj,
poObj: poObj,
salesRepList: salesRepNamesList
}
}
function onSOQuerySucceeded() {
//Do something with the SharePoint List and return an object called soObj.
}
function onSalesRepNamesQuerySucceeded() {
//Do something with the SharePoint List and return an array called salesRepNames.
}
function onPOQuerySucceeded() {
//Do something with the SharePoint List and return an object called poObj.
}
我遇到的问题是 soObj、poObj 和 salesRepNamesList 可能不会按时返回 managementQuery 函数返回。因此,outPutObj 可能在执行第三个函数时定义不正确。请指教。谢谢。
【问题讨论】:
标签: jquery sharepoint promise deferred caml