我在我的JS文件中有这个代码用于淘汰:
function ProductOptionValue(id, name, option) {
var self = this;
self.id = id;
self.name = name;
self.optionID = option;
self.isSelected = ko.observable(false);
}
self.optionValueChanged = function (optionValue, event) {
if (optionValue.isSelected()) {
// .....
} else {
// ...
}
};
绑定看起来像这样:
<ul data-bind="foreach: values">
<li>
<input type="checkbox" data-bind="checked: isSelected, attr: {id: 'ov'+id}, event: {change: $root.optionValueChanged}"/>
<label data-bind="text: name, attr: {for: 'ov'+id}"></label>
</li>
</ul>
问题在IE(10)和Chrome中,当调用optionValueChanged时,我在optionValue中获取isSelected的旧值,但在FF中获得一个新值,因此所有逻辑都被反转。
之前有没有人遇到这种不一致?我应该怎么做才能阻止它。
我使用的是库2.2.1版
答案 0 :(得分:1)
我订阅了我已经绑定到复选框的observable,这似乎适用于IE 10和Chrome和FF:
var isChecked = ko.observable(false);
isChecked.subscribe(function (newValue) {
if (newValue) {
// This is the new value of the checkbox observable
}