Knockout.js 取消选中并单击两者(防止双复选框切换)

Knockout.js 取消选中并单击两者(防止双复选框切换),knockout.js,Knockout.js,我对复选框的描述如下: <input id="checkbox1" type="checkbox" data-bind=" click: function () { handle_compare($element) }, checked: is_product_compared"> .handle_compare()只是反转可观察的“is_product_compare”,问题是允许此复选框有正常行为,如果我单击它,它似乎会出现双切换,并且我从未看到更改 如果我

我对复选框的描述如下:

<input id="checkbox1" type="checkbox" data-bind="
    click: function () { handle_compare($element) },
    checked: is_product_compared">

.handle_compare()只是反转可观察的“is_product_compare”,问题是允许此复选框有正常行为,如果我单击它,它似乎会出现双切换,并且我从未看到更改

如果我绑定了handle_compare to button-all,则复选框将正常切换。是否有一种方法允许这两种绑定

您可以在这里看到一个演示,按钮正常,但复选框有错误的行为


您需要内联单击处理程序返回true:

要么:

<input id="checkbox1" type="checkbox" data-bind="
    click: function () { handle_compare($element); return true; },
    checked: is_product_compared">

或者(因为handle_compare已经返回true):


非常感谢,我读到关于返回“true”的消息,但它被放错了位置。。我希望这个答案对其他人有所帮助。
<input id="checkbox1" type="checkbox" data-bind="
    click: function () { return handle_compare($element) },
    checked: is_product_compared">