IE8淘汰错误-无法处理绑定

IE8 knockout error - Unable to process binding

本文关键字:处理 绑定 淘汰 错误 IE8      更新时间:2023-09-26

我有一个这样的视图模型,

var sectorViewModel = function() {
    this.currentValue = ko.observable();
    this.previousValue = ko.observable();
    ....
    this.maxValue = ko.computed(function() {
        return Math.max(this.currentValue(), this.previousValue(), ...);
    }, this);
}
ko.applyBinding(sectorVM, document.getElementById("divSector");

这是我进行数据绑定的html片段,

<div id="divSector">
    ...
    <div class="bar" data-bind="style: {width: (currentValue()*100)/maxValue() + '%'}"></div>
    ...
</div>

除IE8外,在所有浏览器中都可以正常工作。在IE8中,我在开发工具-中看到了这个错误

Invalid argument. Unable to process binding "style: function() {return..."

知道我该如何在IE8中使用它吗?

谢谢。

调查从计算中返回的确切结果。

根据以下内容:

https://github.com/knockout/knockout/issues/525

较新的浏览器可能会处理诸如xx.asmanydecimalplacesrequired%之类的结果,但可能与IE8不兼容。您应该确保返回的值是与IE8兼容的宽度样式属性——例如,将其修剪到小数点后2位——这是我要尝试的第一件事。

如果这有帮助的话,请告诉我,因为我完全是通过研究弄清楚的,如果是这样的话,别忘了投票;P