gpt4 book ai didi

javascript - 在 InquirerJS 中传递选择的答案?

转载 作者:行者123 更新时间:2023-12-03 02:33:24 26 4
gpt4 key购买 nike

我如何才能从上一个问题中获得答案并转到下一个问题以供询问者JS选择?我知道它是异步的,但我不确定如何在这里创建 promise 。任何进一步的见解和帮助都会很棒。

示例:

var questions = [{
name: 'menu',
type: 'checkbox',
message: 'Which food do you like eating?',
choices: ['pizza', 'hotdog', 'hamburger', 'sandwiches'],
}, {
name: 'favorite',
type: 'checkbox',
message: 'Which one do you like most?',
choices: answers.menu, <------- doesn't work because it is asynchronous
};

最佳答案

根据文档choises可以是一个函数。

var inquirer = require('inquirer');

var questions = [
{
name: 'menu',
type: 'checkbox',
message: 'Which food do you like eating?',
choices: ['pizza', 'hotdog', 'hamburger', 'sandwiches'],
},
{
name: 'favorite',
type: 'checkbox',
message: 'Which one do you like most?',
choices: (answers) => {
return answers.menu;
}
},
];

inquirer.prompt(questions).then(answers => {
console.log(answers);
});

关于javascript - 在 InquirerJS 中传递选择的答案?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48638144/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com