inquirer
.prompt([
{ type:'list',
message: "Select an option",
name: 'walletOptions',
choices: [
'Wallet',
'Normal Transaction',
'Arbitrage'
]}
])
.then(({walletOptions}) => {
if (walletOptions === 'Wallet') {
//let them view and edit wallet
inquirer
.prompt([
{ type:'list',
message: "Select an account",
name: 'accountOptions',
choices: [
'1',
'2',
'3',
'<<< Quit'
]}
])
.then(({accountOptions}) => {
if (accountOptions === '1') {
//display account info for one
var walletOne = wallet[1]
console.log(walletOne);
} else if (accountOptions === '2') {
//display account info for two
var walletTwo = wallet[2]
console.log(walletTwo);
} else if (accountOptions === '3') {
//display account info for three
var walletThree = wallet[3]
console.log(walletThree);
} else {
return ;
}
})
} else if (walletOptions === 'Normal Transaction') {
//continue with mainswap.js
var normalTx = require("./mainswap");
mainswap.deploy()
} else {
//continue with ...
}
});
除了使用一堆 if 之外,有没有一种方法可以为不同的选择显示不同的选项,而不必像我一样直接为每个选项指定?我认为有 .when 选项,但我不确定在这种情况下如何使用它。我试图让他们选择钱包选项,然后让他们查看他们选择的钱包。此外,当用户选择 <<< 退出键时,我似乎无法弄清楚如何将用户发送回菜单的开头,因此任何输入如何做到这一点都会很好