Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

116
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda