Necesito ayuda en simplificar unos If

  • Autor Autor JancoBH
  • Fecha de inicio Fecha de inicio
JancoBH

JancoBH

Gamma
Programador
¡Usuario con pocos negocios! ¡Utiliza siempre saldo de 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:
 
¿Te sirvió? Únete a la conversación

Con tu cuenta gratis puedes responder, escribirle al autor por mensaje privado y comprar con Saldo retenido: el pago se libera cuando recibes lo acordado.

Toma 30 segundos · vuelves a este tema al 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
 
Atrás
Arriba