Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

171
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!