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

115
Visualizações
Jquery+React $.each() not rebinding my callback to the DOM element?

I'm not sure if React is explicitly relevant, other than that it requires me to explicitly bind the function which is calling .each().

But I have a submit() function for a dynamically generated form. I am using .each() to iterate through the various fields to get the data. As I understand, the callback I supply to .each() is supposed to become bound to the DOM element for the current iteration. Instead however, this is referring to the class that the submit() function is bound to. It looks roughly like:

class MyForm extends React.Component {
    constructor(props) {
        super(props);
        this.submit = this.submit.bind(this);
    }

    submit() {
        $('input.my-input').each(() => {
            console.log(this);
        });
    }
}

And my class object is being printed to the devtools console instead of the DOM element, ie.:

> MyClass {props:..., refs:..., state:...}

I'm assuming this is somehow an issue with submit() being bound. How can I otherwise work around this?

about 4 years ago · Juan Pablo Isaza
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