gpt4 book ai didi

javascript - IE8 knockout 错误 - 无法处理绑定(bind)

转载 作者:行者123 更新时间:2023-12-03 09:45:47 25 4
gpt4 key购买 nike

我有一个像这样的 View 模型,

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");

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

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

在除 IE8 之外的所有浏览器中都能正常工作。在 IE8 中,我在开发工具中看到此错误 -

参数无效。无法处理绑定(bind)“style: function() {return...”

知道如何让它在 IE8 中运行吗?

谢谢。

最佳答案

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

根据以下内容:

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

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

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

关于javascript - IE8 knockout 错误 - 无法处理绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31037759/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com