【发布时间】:2017-06-04 23:12:56
【问题描述】:
我试图弄清楚如何使用 promises 使用 yeoman 生成器进行递归提示。我正在尝试生成一个表单生成器,它将首先询问表单组件的名称,然后为每个输入(即:名字、姓氏、用户名等)询问一个名称(将用作 id)。我已经使用回调找到了这个问题的答案,但我想坚持承诺。下面是我到目前为止的代码以及我试图为递归做的但没有工作的代码。任何帮助和建议都非常感谢您提前谢谢!
const Generator = require('yeoman-generator')
const questions = [
{ type: 'input',
name: 'name',
message: 'What is the name of this form?',
default: 'someForm'
},
{
type: 'input',
name: 'input',
message: 'What is the name of the input?'
},
{
type: 'confirm',
name: 'askAgain',
message: 'Is there another input to add?'
}
]
module.exports = class extends Generator {
prompting() {
return this.prompt(questions).then((answers) => {
if (answers.askAgain) {
this.prompting()
}
this.userOptions = answers
this.log(this.userOptions)
})
}
}
【问题讨论】:
标签: javascript recursion yeoman yeoman-generator