Preciso de ajuda para simplificar uns If

  • Autor Autor JancoBH
  • Data de início Data de início
Tradução em andamento: em alguns minutos este tópico estará em português. Por enquanto, o conteúdo está no original em espanhol. Ver original
JancoBH

JancoBH

Gamma
Programador
Usuário com poucas negociações! Use sempre o saldo do ForoBeta!
Saludos, necesito ayuda en algo que puede ser una boberia, tengo este código de un Pagination y me gustaría poder simplificarlo :encouragement:

Si la pagina es 1 entonces inicia en 0 y 15, si es 2 inicia en 15 y 30, si es 3 en 30 y 45 y así va de 15 en 15 pero el problema es que si la data aumenta de 90 tendría que hacer mas if

HTML:
changeEmpleados(e) {
    if (e === 1) {
      this.init = 0;
      this.end = 15;
    } else if (e === 2) {
      this.init = 15;
      this.end = 30;
    } else if (e === 3) {
      this.init = 30;
      this.end = 45;
    } else if (e === 4) {
      this.init = 45;
      this.end = 60;
    } else if (e === 5) {
      this.init = 60;
      this.end = 75;
    } else if (e === 6) {
      this.init = 75;
      this.end = 90;
    }

  }

gracias :encouragement:
 
Foi útil? Participe da conversa

Com sua conta grátis você pode responder, mandar mensagem privada ao autor e comprar com Saldo retido: o pagamento é liberado quando você recebe o combinado.

Leva 30 segundos · você volta a este tópico ao terminar
Acá te va algo un poquito más dinámico 😉

PHP:
changeEmpleados(e) {
    if (e === 1) {
      this.init = 0;
      this.end = 15;
    }else{
      this.init = (15 * e) - 15;
      this.end = 15 * e;
    }
  }
 
Acá te va algo un poquito más dinámico 😉

PHP:
changeEmpleados(e) {
    if (e === 1) {
      this.init = 0;
      this.end = 15;
    }else{
      this.init = (15 * e) - 15;
      this.end = 15 * e;
    }
  }

Gracias :encouragement: sabia que iba a hacer algo simple pero no me llegaba a la cabeza :witless:
 
Acá te va algo un poquito más dinámico 😉

PHP:
changeEmpleados(e) {
    if (e === 1) {
      this.init = 0;
      this.end = 15;
    }else{
      this.init = (15 * e) - 15;
      this.end = 15 * e;
    }
  }

Buena implementacion de codigo
 
Voltar
Topo