switch case JavaScript: Variable Django is not recognized

0

I have a function that makes a switch case to select a specific time for a certain element. The problem is that the cases are generated based on the number of elements in the database using the ID as the case number.

example:

swicth(---metodod de API de FOTORAMA -- ){
    case {{image.id}}:
    //assignacion de tiempos
}

I know that the expression inside the case is correct because if I do a console.log (); I see the id that is supposed to match with the cases

the problem that is does not activate any of the example of my function

dynamic code example:

$(function () {
      $('.fotorama').on('fotorama:showend',function(){
            console.log(fotorama.activeFrame.id);

            switch(fotorama.activeFrame.id){

                {% for imagen in imagenes %}
                case {{ imagen.id }}:

                    fotorama.setOptions({
                        autoplay : {{ imagen.duracion }}
                    });
                    break;
                {% endfor %}

                default:
                    fotorama.setOptions({
                        autoplay: 2000
                    });
                    break;
            }
        })
    });

code already generated:

$(function () {
      $('.fotorama').on('fotorama:showend',function(){
            console.log(fotorama.activeFrame.id);

            switch(fotorama.activeFrame.id){


                case 44:

                    fotorama.setOptions({
                        autoplay : 5000
                    });
                    break;

                case 45:

                    fotorama.setOptions({
                        autoplay : 20000
                    });
                    break;


                default:
                    fotorama.setOptions({
                        autoplay: 2000
                    });
                    break;
            }
        })
    });

getSlides();

and this is what I get in console:

    
asked by victor reyes1 23.09.2017 в 04:30
source

1 answer

-1

In JavaScript the element switch only receives parameters of type Integer so if you convert the variable fotorama.activeFrame.id before it happens to swicth with a parseInt it will work.

For example:

switch(parseInt(fotorama.activeFrame.id)){
    ...
}
    
answered by 28.01.2018 в 05:09