Before displaying the ch data I have to wait for the storage of this data in ch! I used setTimeout in the display function "updateSelectMenu (ch) " to wait for the end of the function formatStockInfo (xml) ! My problem is how to accede to the promised values in the function "updateSelectMenu (ch) " The format of ch obtained is :
Promise {[[PromiseStatus]]: "resolved", [[PromiseValue]]: Array(3)}
function formatStockInfo(xml) {
console.log("formatStockInfo");
var ch = [];
var NMPRES = "";
var jsonObj = JSON.parse(xml2json(xml, ""));
var nom = jsonObj.SubmitResponse.occurrences.occurrence.filter(x => x["@datasection"] === "KT")[0].data.filter(x => x.item === "NMPRES")[0].value;
var matcle = jsonObj.SubmitResponse.occurrences.occurrence.filter(function(x) {
return x["@datasection"] === "LM"
})[0].data.filter(x => x.item === "MATCLE")[0].value;
var dossier = jsonObj.SubmitResponse.occurrences.occurrence.filter(function(x) {
return x["@datasection"] === "LM"
})[0]["@dossier"];
console.log(nom, matcle);
ch.push({
"nom": nom,
"matcle": matcle,
"dossier": dossier
}); }
function updateSelectMenu(ch) {
setTimeout(function() {
for (var key in ch) {
if (ch[key].matcle === matricule) {
txt += "<option value='" + ch[key].dossier + "'" + firstSelect(firstIter) + ">" + ch[key].nom + "</option>";
}
}
$('#population').html(txt)
}, 1000);}
cell1.innerHTML = '<input type="submit" onclick="RechercheFiltree().then(getStockArray).then(getStocks).done(updateSelectMenu);" value="Rechercher" >';