0

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"  >';
fiolafafa
  • 11
  • 1
  • 5
  • Possible duplicate of [return value after a promise](https://stackoverflow.com/questions/22951208/return-value-after-a-promise) – Igor Soloydenko Oct 15 '17 at 22:59
  • what is function `RechercheFiltree`? and `getStockArray`? and `getStocks`? You haven't shown code or even attempted to say what they do. Why have you included code for function `formatStockInfo`? It seems unrelated – Jaromanda X Oct 16 '17 at 03:03
  • @JaromandaX those are other function that I call them before `formatStockInfo` ! `getStocks` call `formatStockInfo` when it terminates execution. – fiolafafa Oct 16 '17 at 09:58
  • my point was that you've shown code that isn't called, and referred to functions that you haven't shown - hard to guess what you've done wrong – Jaromanda X Oct 16 '17 at 10:00

0 Answers0