Knockoutjs and click on parent etc

I have a table with a row. The line has TD (with a flag in it), and on TD I have a click function. So when TD is pressed, the checkbox will be checked / unchecked.

It works fine when I click on TD, but when I click on the checkbox (visual) the value of the checkbox does not change (it is not checked / not checked)

Required Situation:

  • When I click this checkbox, the (visual) value of the checkbox changes, and I can call a function (for example, to call AJAX)

  • When I click on TD, the (visual) value of the checkbox changes, and I can call the function. (e.g. to call AJAX)

How can we achieve this?

Code example

+5
source share
5 answers

, label, . , td:

<td>
    <label style="display: block">
        <input type="checkbox" data-bind="checked: checkBox" />
    </label>
</td>

. http://jsfiddle.net/mbest/LsxSh/

+1

, click TD checkbox, , checkbox , checkbox, TD ( ). , checkbox TD. Knockout : click:function(){return true}, clickBubble:false.

: http://jsfiddle.net/mbest/Eatdh/12/

, label - (. ).

+10

The Td event seems to override the input input click event

+1
source

clicking on the checkbox brings up the clicker code for td:

self.checkBox(!self.checkBox());

this removes the check.

0
source

It's not exactly DRY, but fast and functional: fiddle

<td data-bind="click:tdClick">
      <input type="checkbox" data-bind="checked: checkBox, click:tdClick" />
</td>
0
source

All Articles