简体   繁体   中英

Using array destructuring as the value for multiple-choice questions with Inquirer?

I have a dilemma, my code is:

    inquirer.prompt([
    {
      type: 'checkbox',
      name: 'Keywords',
      message: 'Please select the keywords you would like to use with a maximum of 5.',
      choices: [
        NewDescriptionKeys[0],
        NewDescriptionKeys[1],
        NewDescriptionKeys[2],
        NewDescriptionKeys[3],
        NewDescriptionKeys[4],         
      ]
    }
  ]).then(function (answers) {}//other non-related code is here

My problem is, I can sometimes have more then 5 results, and need to display all of them, so the user can select the ones they want to use, and deselect the ones they don't, I've tried just putting each array until I reach the possible maximum that could be returned, but that just puts undefined's everywhere, any suggestions?

Why not this:

{
  type: 'checkbox',
  name: 'Keywords',
  message: 'Please select the keywords you would like to use with a maximum of 5.',
  choices: NewDescriptionKeys
}

Simplify it with

    {
      type: 'checkbox',
      name: 'Keywords',
      message: 'Please select the keywords you would like to use with a maximum of 5.',
      choices: NewDescriptionKeys
    }

and

Please use the Spacebar to select not enter(return)

 (Press <space> to select, <a> to toggle all, <i> to inverse selection)

If you press the enter without selection(without pressing spacebar) then it submits the unselected result with is the empty array.

Enter work as submit

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM