Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

79
Vistas
Options in inquirer.js javascript inputs

Instead of using a bunch of ifs, is there a way to show different options for different selections rather than having to specify directly for each one like I am doing? I think there is the .when option, but I am not really sure how to use it in this situation.

I am trying to let them select the wallet option and then let them view the wallet that they choose. Also, I can't seem to figure out how to send the user back to the beginning of the menu when they select the <<< quit key, so any input into how to do that would be good.

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 ...
    }
});
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Use "rawlist" instead of "list" in the type attribute as in the Official Example

Also remove the unwanted "}" after the choices list.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda