击倒选中并单击两者(防止双复选框切换)
Knockout checked and click both (prevent double checkbox switch)
我有这样描述的复选框:
<input id="checkbox1" type="checkbox" data-bind="
click: function () { handle_compare($element) },
checked: is_product_compared">
.handle_compare() 只是反转可观察的 "is_product_compared",问题是允许此复选框的正常行为,如果我单击它,似乎它是双重开关,但我从未看到变化。
如果我将 handle_compare 绑定到按钮 - 一切正常,复选框会正常切换。有没有办法允许这两个绑定?
你可以在这里看到一个演示,按钮没问题,但是复选框有错误的行为。
您需要内联点击处理程序 return true:
http://jsfiddle.net/g5rpcw2c/2/
任一:
<input id="checkbox1" type="checkbox" data-bind="
click: function () { handle_compare($element); return true; },
checked: is_product_compared">
或(因为 handle_compare 已经 return 为真):
<input id="checkbox1" type="checkbox" data-bind="
click: function () { return handle_compare($element) },
checked: is_product_compared">
我有这样描述的复选框:
<input id="checkbox1" type="checkbox" data-bind="
click: function () { handle_compare($element) },
checked: is_product_compared">
.handle_compare() 只是反转可观察的 "is_product_compared",问题是允许此复选框的正常行为,如果我单击它,似乎它是双重开关,但我从未看到变化。
如果我将 handle_compare 绑定到按钮 - 一切正常,复选框会正常切换。有没有办法允许这两个绑定?
你可以在这里看到一个演示,按钮没问题,但是复选框有错误的行为。
您需要内联点击处理程序 return true:
http://jsfiddle.net/g5rpcw2c/2/
任一:
<input id="checkbox1" type="checkbox" data-bind="
click: function () { handle_compare($element); return true; },
checked: is_product_compared">
或(因为 handle_compare 已经 return 为真):
<input id="checkbox1" type="checkbox" data-bind="
click: function () { return handle_compare($element) },
checked: is_product_compared">