0

I have this next code which I am trying to print some data on screen. The issue which I am facing is that each function is being executed twice so therefore the console.log appears on my console twice also.

It is really bizarre that this thing is happening. My code goes like this: I tried doing it with window.onload and also tried to import the functions inside the document.ready but no luck.

If anyone can give me any hint what I am doing wrong, that would be really appreciating.

<body class="stretched">
    <div id="wrapper" class="clearfix">
        <!--Cargamos Layout de NavBar -->
        @Html.Partial("_NavBar_DataUser")
        <!--Fin de Carga -->
        <section id="carouselComercialTop" class="mt-auto">
            <div class="content-wrap">
                <!--Cargamos el caroussel stático -->
                @Html.Partial("_Layout_Caroussel")
            </div>

        </section>
        @Html.Partial("_Layout_Medicina360")

        <iframe class="pt-4" frameborder="0" width="100%" height="100%" src='#' name="zoom360" id="zoom360" style="display:none;"></iframe>
    </div>
    @Html.Partial("_Layout_DataUserFooter")
    <script type="text/javascript" src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
    <script type="text/javascript" src="/lib/slick-1.8.1/slick/slick.min.js"></script>
    <link rel="stylesheet" type="text/css" href="/lib/slick-1.8.1/slick/slick-theme.css" />
    <link rel="stylesheet" type="text/css" href="/lib/slick-1.8.1/slick/slick.css" />
</body>
    <script>
      window.ca_model = [];
      let stringJSONConsultaBuscador = ("@Context.Session.GetString("ConsultaBuscador")");
      window.ca_model = JSON.parse(stringJSONConsultaBuscador.replace(/&quot;/g, '"'));
      let especialistas = window.ca_model.listaEspecialistas;
      let especialista360varon = [];
      let especialista360mujer = [];
      let especialista360nino = [];
      let listaEspecialistas = window.ca_model.listaEspecialistas;
      let varon360 = listaEspecialistas.filter(b => b.hombres360 !== false);
      let mujer360 = listaEspecialistas.filter(b => b.mujeres360 !== false);
      let ninos360 = listaEspecialistas.filter(b => b.ninos360 !== false);

      especialista360varon.push(varon360);
      especialista360mujer.push(mujer360);
      especialista360nino.push(ninos360);

      especialista360varon = especialista360varon[0];
      especialista360mujer = especialista360mujer[0];
      especialista360nino = especialista360nino[0];

    function loadEspecialista360Varon(especialista360varon) {
        console.log(especialista360varon);
    }
    function loadEspecialista360Mujer(especialista360mujer) {
        console.log(especialista360mujer);
    }
    function loadEspecialista360Nino(especialista360nino) {
        console.log(especialista360nino);
    }

    window.onload = function () {
        loadEspecialista360Varon(especialista360varon);
        loadEspecialista360Mujer(especialista360mujer);
        loadEspecialista360Nino(especialista360nino);
    };
    $(document).ready(function () {
        let mobile = window.matchMedia('(max-width: 767px)').matches;
        let url = window.location.href;

        $('.link-carousel').each(function(){
            let href = $(this).attr("href");
            let container = $(this).parent().parent();
            if (url.indexOf(href) > -1){
                container.css({"background-color" : "rgb(173, 124, 177)"});
            }
        });

        let cuadroMedicoButton = document.getElementById("cuadroMedicoButton");
        cuadroMedicoButton.setAttribute("href", "/CuadroAsistencial/AsistenciaSpecialistas");
        if (mobile) {
            $('#mainRow').removeClass("d-flex");
            $('#mainCol').removeClass("d-flex");
            $('#containerMedicina360').replaceClass("py-5 py-2");
        }
    });
</script>
Oris Sin
  • 1,023
  • 1
  • 13
  • 33
  • Can you narrow down to the minimal code required to recreate the issue? Maybe convert to a snippet with your data as a js variable (if it's needed to recreate) so we can see it working. – freedomn-m Jan 21 '21 at 11:03
  • Does this help to diagnose the issue? https://stackoverflow.com/a/6219693/2181514 – freedomn-m Jan 21 '21 at 11:06
  • 1
    This seems a possibility: https://stackoverflow.com/a/10727036/2181514 – freedomn-m Jan 21 '21 at 11:07

0 Answers0