gpt4 book ai didi

javascript - while 循环中的链接 promise 未正确返回值

转载 作者:行者123 更新时间:2023-12-03 02:40:38 24 4
gpt4 key购买 nike

下面的代码不会引发语法错误,但在查询所有列表之前,首先执行在数据表上呈现数据的 THEN 语句

这段代码的意图是什么,有很多具有相似名称的共享点列表:Bill Cycles、Bill Cycles Archive1....N.

我需要查询所有这些列表以进行特定查询,并将所有结果连接到结果变量中,然后使用该变量与数据表插件进行渲染,但正如第一个语句中所解释的那样,外部 .then在开始时执行,inner then 在页面渲染完成后执行。

function GetData(billCycleId, clientCode, jobCodes, engagementCode) {
var deferred = $q.defer();
var enhanceFunctions = [
function(searchResultRow) {
return spService.AddHyperLinkOnFields(searchResultRow, config.HyperLinks);
},
function(searchResultRow) {
return spService.AddPresenceOnFields(searchResultRow, config.UserFields);
},
function(searchResultRow) {
return spService.FormatDateFields(searchResultRow, config.DateFields, generalConfig.DateTimeFormat);
},
function(searchResultRow) {
return spService.AddImageMapping(searchResultRow, config.ImageFields);
},
function(searchResultRow) {
return spService.FormatNumberFields(searchResultRow, config.NumberFields);
}
];

var selectProperties = spService.TransformFieldsToSelectProperties(config.Fields);
var extendedSelectProperties = selectProperties.slice(); // copy array
var hyperLinkedProperties = spService.TransformFieldsToSelectProperties(config.HyperLinks)
extendedSelectProperties = extendedSelectProperties.concat(hyperLinkedProperties);
var result =[];
spService.GetAllListsFromWeb()
.then(function (lists) {
var listEnumerator = lists.getEnumerator();
return $q.all(
(function(){
var promises = [];
while (listEnumerator.moveNext()) {
var oList = listEnumerator.get_current();
var title = oList.get_title();
var id = oList.get_id();
if (title.indexOf('Bill Cycles') !== -1) {
// Get data from SP !!! this is also async and returns a promise
// add the promise to promises array and wait for all to finish
// look above in Promise.all
promises.push(
GetRelatedBillCyclesFromList(
id,
extendedSelectProperties,
billCycleId,
clientCode,
jobCodes,
engagementCode,
enhanceFunctions
)
.then(function (data) {
var trimmedData =
spService
.SpSearchQuery
.TrimSearchResultsToSelectProperties(
data,
selectProperties
);

trimmedData.forEach(function(item){ // loop over source array
result.push(item); //append to result array
});
})
);
}
}
//return promises
})() //IIFE returning an array of promises
);
})
.then( //The promise is used to execute something after all promises are resolved, but the results are build in the result array, no need to use data
function(data){
//var resultadata = data;
var dataTable = $(tableSelector).DataTable();
dataTable.clear().rows.add(result).columns.adjust().draw(); // Resize columns based on new data sizes
vm.ValidDataLoaded = true;
}
);

}

最佳答案

您将 undefined 传递给 $q.all ,因为 //return Promise 已被注释掉。取消注释应该可以解决您的问题。

关于javascript - while 循环中的链接 promise 未正确返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48340466/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com