Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

277
Visualizações
Get value from javascript dict in odoo template's script tag

I need to get the value of elt.innerHTML and pass it to fromPage[j].textContent.

Function borrowed from GitHub.

Currently vars['hiddenNumber'] is returning undefined.

elt.style.visibility = "hidden"; works as intended tho.

I believe this might be related with variable scopes, but can't seem to find a way to create a global variable. Tried to update window.value, but got an error that window is not defined.

Using odoo 13, wkhtmltopdf 0.12.5.

<script>
    function subst() {
        var vars = {};
        var x = document.location.search.substring(1).split('&amp;');
        for (var i in x) {
            var z = x[i].split('=', 2);
            vars[z[0]] = unescape(z[1]);
        }
        var index = vars['webpage'].split('.', 4)[3]

         var operations = {
                    // other operations
             'hidden_page_number': function (elt) {
                 elt.style.visibility = "hidden";
                 vars['hiddenNumber'] = elt.innerHTML;  // This value
             },
         };

         for (var klass in operations) {
             var y = document.getElementsByClassName(klass);
             for (var j=0; j&lt;y.length; ++j)
             operations[klass](y[j]);
         }

         var fromPage = document.getElementsByClassName('page');
         for(var j = 0; j&lt;fromPage.length; j++)
         fromPage[j].textContent = vars['hiddenNumber'];  // Required here

         var toPage = document.getElementsByClassName('topage');
         for(var j = 0; j&lt;toPage.length; j++)
         toPage[j].textContent = vars.sitepages;
 }
</script>

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

just a suggestion: you define vars outside the closure and then define closure where try to update vars but I suppose that inside the closure it creates new scope for vars and that's why vars is not updated outside

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda