javascript - Inquirer.js javascript 输入中的选项
问题描述
有没有一种方法可以为不同的选择显示不同的选项,而不是使用一堆if
s,而不是像我一样直接为每个选项指定?我认为有这个.when
选项,但我不确定在这种情况下如何使用它。
我试图让他们选择钱包选项,然后让他们查看他们选择的钱包。此外,当用户选择 <<< 退出键时,我似乎无法弄清楚如何将用户送回菜单的开头,因此任何输入如何做到这一点都会很好。
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 ...
}
});
解决方案
推荐阅读
- hana - 在哈纳恢复运输
- angular - 不会显示 Maticons
- c++ - nullptr 可以用作类型吗?
- excel - 自定义函数在 VBA 中工作并在 Excel 单元格中调用时返回 #VALUE“错误数据类型”
- javascript - 在 Node.js 中提供发布请求后如何重定向到另一个页面?
- javascript - 如何将条带自定义结帐令牌发布到烧瓶后端
- c# - C# 中的 PictureBox 接受 .PNG 图像?
- mysql - MySQL - DBI:如何判断第一列是否为自增列?
- css - 媒体屏幕 - 使按钮居中
- ios - didUpdate userLocation:用于谷歌地图 ios swyft 的 MKUserLocation