javascript 当 Yeoman 上的提示前一个为真时,如何执行其他提示?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18688389/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How execute other prompt when prompt previous is true on Yeoman?
提问by Fuechter
How execute prompt2 when prompt1 is true on Yeoman as shown below?
如下所示,当 Yeoman 上的 prompt1 为 true 时,如何执行 prompt2?
var prompts = [
{name: 'prompt1', message: 'Ask 1?'},
{name: 'prompt2', message: 'Ask 2?'}
];
回答by Stephen
Yeoman uses a thing called Inquirer.jsfor the prompt system. Here's an example of how you can ask Question 2 if Question 1 was true:
Yeoman 使用名为Inquirer.js的东西作为提示系统。下面是一个示例,说明如果问题 1 为真,您可以如何问问题 2:
inquirer.prompt([{
name: 'movie',
type: 'confirm',
message: 'Have you seen a movie lately?'
}, {
when: function (response) {
return response.movie;
},
name: 'good-or-not',
message: 'Sweet! Was it any good?'
}], function (response) {});
From the Inquirer.js documentation:
来自 Inquirer.js 文档:
when: (Function)Receive the current user answers hash and should return true or false depending on wheter or not this question should be asked.
when: (Function)接收当前用户的答案散列,并根据是否应询问此问题而返回 true 或 false。