我有一个Javascript链式承诺,只处理question
承诺。注意到progress
承诺后,question
承诺有效。
我需要更改哪些来处理这两个承诺?
nextQ: function(item){
var percentQuestion = 100/this.numberQuestions;
var progress = new Promise(
function (resolve, reject) {
console.log(percentQuestion);
var elem = document.getElementById("myBar");
var numericWidth = elem.style.width.replace(/\D/g,'');
var currentWidth = +numericWidth;
var newWidth = +numericWidth + +percentQuestion;
var id = setInterval(frame, 10);
function frame() {
if (currentWidth >= newWidth) {
clearInterval(id);
} else if(currentWidth < 100){
currentWidth++;
elem.style.width = currentWidth + '%';
}
else{
console.log('max');
};
};
resolve();
}
);
var question = new Promise(
function (resolve, reject) {
var newKey = item + 1;
var y = document.getElementById('question' + item);
var x = document.getElementById('question' + newKey);
if( y.style.display === 'block'){
y.style.display = 'none';
x.style.display = 'block';
console.log("Changed");
};
resolve();
}
);
Promise.all([progress,question]).then(function () {
console.log('processed');
})
.catch(function (error) {
console.log(error.message);
});
},