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

183
Visualizações
How to call function using Nunjucks?

I want to call the jQuery function in HTML using Nunjucks, but it's giving me an error. I have imported the JS file into the HTML file.

Error: Unable to call 'fooName', which is undefined or falsey

Does anyone know why I can't call the function? Here is my code example:

<a class="btn" onclick="{{fooName(test)}}" href="#">Click me!</a>
$(document).ready(() => {
  const fooName = (name) => {
    console.log(`${this.name}`)
  };
});
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

My situation was a bit different but still I think it works in this case too

The idea is to add a function to the global window object

Within the view render method that passes variables to nunjucks I added this function

var self = this;

window.onClick = function (id) {
 // self.fetchData(id);
 // Do something
}

and within nunjucks

<a class="btn" onclick="window.onClick({{item.id}})">Click me!</a>

it works perfectly.

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