我很好奇是否可以根据用户从之前的提示中选择的内容来更改提示的默认消息.
现在我的第一个提示只是一个列表,用户选择一个选项,并询问其他一些问题.请注意,这两个在两个不同的生成器中运行
YeomanGenerator.prototype.askForThings = function askForThings() {
var cb = this.async();
var prompts = [{
name: 'questionOne',
type: 'list',
message: 'Message, message?',
choices: ['optionOne', 'optionTwo', 'optionThree', 'optionFour', 'optionFive', 'optionSix', 'None'],
filter: function(value) {
return value.toLowerCase();
}
}
Run Code Online (Sandbox Code Playgroud)
然后,在下一部分中,将询问用户放置此目录的目录.但是,我想知道是否可以根据用户选择的内容更改默认位置questionOne.现在这个default选项只是空洞的.
YeomanGenerator.prototype.askForMoreThings = function askForMoreThings() {
var cb = this.async();
var questionOne = this.questionOne;
{
name: 'questionOneDirectory',
message: 'Question question',
default: function(default) {
if (this.questionOne === 'optionOne') {
this.default("'/directory/_one'");
}
else if (this.questionOne === 'optionTwo') {
this.default("'/directory/_two'");
}
{
//etc
}
},
filter: function(value) { return value.split('/').pop(); },
when: function() {
return questionOne;
},
Run Code Online (Sandbox Code Playgroud)
甚至可以在这里更改默认消息吗?这只是一件小事,但我想知道它是否可能.提前致谢.
why*_*eee 13
对于那些搜索问题主题答案的人来说,这是一个通用的解决方案.default属性接受一个函数并传递一个包含所有先前答案的对象.使用该对象在运行时生成默认值:
this.prompt([{
name: 'title',
message: 'Your title?',
default: 'Mr.'
}, {
name: 'name',
message: 'Your name?',
default: function(answers) {
return answers.title + ' Smith';
}
}]);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
797 次 |
| 最近记录: |