我正在使用 JS 和inquirer
. 从下面的代码中,我希望从两个 for 循环中得到一些 console.log() 。但是,即使两者都包含值,也没有checkChoices
console.log answers
。
JS
view(){
let checkChoices = [];
for(let i = 0; i < this.list.length; i++){
checkChoices.push(this.list[i].text);
}
let viewList = [
{
type: 'checkbox',
name: 'command',
message: 'Your Checklist',
choices: checkChoices
}
]
console.log(checkChoices.length);
inquirer.prompt(viewList).then((answers) => {
for(let i = 0; i < answers.length; i++){
let answer = answers[i];
console.log("answer", answer)
for(let j = 0; j < checkChoices.length; j++){
console.log("choice", checkChoices[j])
if(answer == checkChoices[j]){
this.list[j].complete = true;
}
}
}
console.log(this.list);
// this.ask();
})
}
};