Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 使用数组解构作为Inquirer多项选择题的值?_Node.js_Command Line Interface - Fatal编程技术网

Node.js 使用数组解构作为Inquirer多项选择题的值?

Node.js 使用数组解构作为Inquirer多项选择题的值?,node.js,command-line-interface,Node.js,Command Line Interface,我左右为难,我的代码是: inquirer.prompt([ { type: 'checkbox', name: 'Keywords', message: 'Please select the keywords you would like to use with a maximum of 5.', choices: [ NewDescriptionKeys[0], NewDescriptionKey

我左右为难,我的代码是:

    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
我的问题是,我有时会有5个以上的结果,需要显示所有结果,这样用户就可以选择他们想要使用的结果,然后取消选择他们不想要的结果。我已经尝试放置每个数组,直到我达到可能返回的最大值,但这只是将未定义的结果放在所有地方,有什么建议吗

为什么不这样做:

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

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

请使用空格键选择不输入(返回)

(按可选择、全部切换、反向选择)
如果在未选择的情况下按enter键(不按空格键),则它将提交未选择的结果,其中包含空数组


以提交方式输入工作

不知道为什么我没有尝试,非常感谢。它工作得很好。
 (Press <space> to select, <a> to toggle all, <i> to inverse selection)