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

184
Vistas
Data bind click even pass current object to parameter

I am looping through objects and I want to send only current object when clicked.

<div class="box" data-bind="foreach: contacts">
                <div class="contact LightGray-background">
                    <div class="contactType">
                        <label data-bind="text: contactLabel"></label>
                        <label style="font-size:smaller" data-bind="text:contactRole"></label>
                        <img class="hasInfoPopup" data-bind="click: $root.editContact($root)"
                             data-info="Edit Contact" src="~/images/plus-inverted-large.png" style="height:16px;width:16px;float:right" />
</div>

editContact() above is receiving all object values instead of only one.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You are calling editContact in your binding. That means knockout will call it once (passing $root) when ko.applyBindings runs. Assuming editContact does not return a function, the click binding will then be ignored.

If you pass $root.editContact without calling it, knockout will call it on click with two parameters: the current object ($data), and the click event.

data-bind="click: $root.editContact"

If your editContact requires this to refer to $root, you can use .bind:

data-bind="click: $root.editContact.bind($root)"
about 4 years ago · Juan Pablo Isaza Denunciar
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