I have a knockout table with checkboxes (for the example here, I've limited to one checkbox per row). when a checkbox is clicked, it should flip state (as you expect). however, I also have a click event and select event on the table row, which is conflicting with the checkboxes...
<table>
<tbody data-bind="foreach: namespace.divResults.model">
<tr data-bind="click: $root.selectItem, css: {selected: $root.isSelected($data)}">
<td data-bind="text: Title"></td>
<td data-bind="text: Surname"></td>
<td data-bind="text: PostCode"></td>
<td data-bind="checked: Excluded, click: $root.toggleExcluded"></td>
<td data-bind="text: Notes" style="display:none"></td>
<tr>
<tbody>
<table>
<div>
<!-- ko with: $root.selectedItem -->
<textarea data-bind="textInput:Notes"></textarea>
</div>
and the javascript:
(function(ns) {
ns.divResults = null;
var resultsViewModel = function() {
var self = this;
self.model = ko.observableArray();
self.selectedItem = ko.observable();
self.selectItem = function(row){ self.selectedItem(row); }
self.isSelected = function (row) { return self.selectedItem() === row; }
self.toggleExcluded = function() {
return true;
}
}
}
I've tried using clickBubble event, but this blocks the actions of the click event on the table row, which works fine in any case. What I find is that clicking a row's checkbox changes its' state correctly, but then gets put back when the row click does its thing.
Aucun commentaire:
Enregistrer un commentaire