微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在查询器中将上一个答案用于下一个问题

如何解决在查询器中将上一个答案用于下一个问题

我想将上一个答案用于询问者中的下一个问题,这是我的代码

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);

在这里要做的是将第二个问题的答案用于第三个问题。

在这里尝试了解决方法Is there a way to use previous answers in inquirer when presenting a prompt (inquirer v6)?

哪个不适用于我的案子

我该如何解决

谢谢。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。