我想在询问者的下一个问题中使用上一个答案,这是我的代码:
const promptForMissingOptions = async (options) => {
const questions = [];
if (!options.name) {
questions.push({
type: "input",
name: "name",
message: "Name:",
});
}
if (!options.file) {
questions.push({
type: "checkbox",
name: "lots",
message: "Select the categories:",
pageSize: 30,
choices: () => {
const files = helpers.getFileNames();
return Object.keys(files);
},
});
}
if (answers.lots) {
questions.push({
type: "checkbox",
name: "files",
message: "Select the files:",
pageSize: 50,
choices: () => {
const choices = helpers.getFileNames();
return Object.keys(
Object.keys(x)
.filter((key) => answers.lots.includes(key))
.reduce((obj, key) => {
obj[key] = x[key];
return obj;
}, {})
).reduce(
(r, k) =>
r.concat(
new inquirer.Separator(
chalk.underline.bold.bgMagenta(
"------------------------ " + k + " ------------------------"
)
),
choices[k]
),
[]
);
},
});
}
const answers = await inquirer.prompt(questions);
return {
files: options.file ? [options.file] : answers.files,
name: options.name || answers.name,
};
};
let options = await promptForMissingOptions(options);
我在这里要做的是将第二个问题的答案用于第三个问题。
我在这里尝试了解决方案:在呈现提示时,是否有办法在查询器中使用先前的答案(inquirer v6)?
这对我的情况不起作用。
我该如何解决这个问题?
提前致谢。