如何通过javascript

时间:2017-10-15 12:42:09

标签: javascript promise settimeout

在显示ch数据之前,我必须等待ch中存储这些数据! 我在显示功能“ updateSelectMenu(ch) ”中使用了setTimeout来等待 函数formatStockInfo(xml) <的结束/ strong>! 我的问题是如何在函数“ updateSelectMenu(ch) ”中加入承诺的值 获得的ch的格式是:

  

Promise {[[PromiseStatus]]:“已解决”,[[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"  >';

0 个答案:

没有答案